Dusan B. Jovanovic (DBJ) [email protected]
NOTE: only relevant examples from the extensive portfolio
| /* | |
| This is benchmarking of a collection of matrix multiplication algorithms. | |
| Algorithms are kept as simple as possible. No structs are passed as arguments. | |
| No "clever" "generic" matrix macros are used | |
| Different compilers multiplied with different platforms multiplied selection | |
| of data types yield a complex picture of benchmarking results. | |
| Although here is strong hint for you: The simplest algorithm is the fastest. |
| /* | |
| (c) 2022 by [email protected] 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 | |
| /* | |
| comment this in to see the demo | |
| #define DBJ_DEFER_BEGIN_END_DEMO 1 | |
| */ | |
| /* | |
| 2025-MAR [email protected] https://godbolt.org/z/adYP4ach4 | |
| first seen it here https://youtu.be/QpAhX-gsHMs |
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" |