Dynamic Allocation Library - Stacks, Queues, Custom Allocators & Virtual Memory
A feature rich dynamic allocation library.
The code should ideally compile on any C99 compiler. C++ can be supported again but
it will only work through extensions as lots of C99 features do not work in ISO C++.
Patches are welcome to improve support for other compilers and language targets 😃
Tested Platforms:
You only need to copy das.h and das.c into your project.
In one of your C compilation units, include the das.h header and das.c source files like so:
#include "das.h"
#include "das.c"
To use the library in other files, you need to include the das.h header.
#include "das.h"
Most structs, functions and macros have their documentation above them in the das.h header file.
If you are looking for examples, look in the das_examples.c file. There are comments to guide you through and it is suggested that you follow linearally to learn the API.
In that file we have:
This benchmark tests compiling different DasStk implementations vs std::vector. In all tests except cpp_vector_trio_main, we are handling 130 different structures. For each of these, in the main function, a DasStk/std::vector is created and then elements get pushed on to it. These results are on an Intel i5 8250u CPU using Clang 10 on Linux in July 2020. No optimization level has been specified. The results are ordered by time where the fastest test comes first.
We do not have any run-time benchmarks, since these are unlikely to reflect what happens in the real world. At the end of the day, different implementations of stacks and deques are very similar.
However std::vector will generate a optimized function for every implementation. But realistically, where DAS passes in size and align arguments, std::vector have constants precompiled in. As far as I know, thats a very negligible win if any at all. This is the only benefit that I could think of. Personally I don’t think it’s worth the time to compile these different versions of std::vector just for these things.
In DAS, for each operation we have a single function that is used for every type. So there is a single push function for DasStk that is used for all types. These functions are not complicated and will fit in the instruction cache better. So if you are handling many different types of stacks or deques, then DAS is probably better. But again as far as I know, this is probably very negligible if you are not doing huge amounts of data.
I hope this helps, do your own tests if you need 😃