Dusan B. Jovanovic (DBJ) [email protected]
NOTE: only relevant examples from the extensive portfolio
/* | |
(c) 2022 by dbj@dbj.org CC BY SA 4.0 | |
Godbolt: https://godbolt.org/z/ne579e85f | |
The point is here we do not use naked pointer to pass the structs arround | |
we use handles to the preallocated slabs of the same struct | |
thus we do not suffer the perenial modern C dilema: should we pass the | |
structs by value or as pointers to them. |
/* | |
made 2021 by [email protected] | |
https://godbolt.org/z/PjovPPoxf | |
*/ | |
#include <assert.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define FOR(C, R) for (unsigned C = 0; C < R; ++C) |
// ---------------------------------------------- | |
// (c) 2021 by [email protected] | |
// https://dbj.org/license_dbj | |
// https://godbolt.org/z/vaMMrvM85 | |
// ---------------------------------------------- | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> |
#ifndef DBJ_DEFER_BEGIN_END_H | |
#define DBJ_DEFER_BEGIN_END_H | |
/* | |
https://godbolt.org/z/zsYre5Kfj | |
first seen it here https://youtu.be/QpAhX-gsHMs | |
2021-APR [email protected] added macro defer() | |
Two Macros. Usage: | |
Dusan B. Jovanovic (DBJ) [email protected]
NOTE: only relevant examples from the extensive portfolio
I use C, commericaly since 1991. This is where I record what I know about allocating and managing 2D/1D arrays in C. And I keep on revisiting this doc and clarifying it ever more. Many times I cought myself re-discovering what I have stored in here. Please do not repeat the same mistake.
Short answer is this:
+ -- int (*arp)[2][3] // 2D array pointer
V
+------------- int arr[2][3] -----------+
#define DBJ_MTX_TESTING | |
// (c) 2019-2021 by [email protected] | |
// License: CC BY SA 4.0 | |
#include <assert.h> | |
#include <stdlib.h> | |
#include <string.h> // memcpy | |
namespace dbj::mtx { |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<!-- | |
removing this makes HTA:APPLICATION fully functional | |
meta http-equiv="X-UA-Compatible" content="IE=edge" | |
to be tested ... | |
--> |
// https://docs.microsoft.com/en-us/cpp/parallel/concrt/how-to-use-alloc-and-free-to-improve-memory-performance?view=vs-2019 | |
// allocators.cpp | |
// compile with: /EHsc | |
#include <windows.h> | |
#include <ppl.h> | |
#include <crtdbg.h> | |
#include <iostream> | |
#include <vector> | |
#include "dbj_alloc.h" |
// (c) 2019/2020 by [email protected] | |
// CC BY SA 4.0 | |
// | |
// https://wandbox.org/permlink/h8BE47pvLlBMy7wy | |
// clang++ prog.cc -std=c++14 | |
// OK for C++14, C++17, C++2a | |
// | |
// https://dbj.org/c-reduce-compound-to-base-type/ | |
// | |
#include <iostream> |