A simple dynamic allocation library with a stack and double ended queue implementation.
The code should ideally compile on any C and C++ compiler with thread_local and typeof (language extension) support.
C11 and C++11 are the current targets, since this is when thread_local was included in the standards.
If it doesn't mess with the code too much, I am open to supporting older versions if anyone wants to submit some patches :)
You only need to copy das.h and das.c into your project.
In one of your C or 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. When pushing an popping a single element, std::vector could have optimized load and store instructions for intrinsic data types. Instead of how DAS uses a memcpy for all data types. These are the only two benefits that I could think of. Personally I don't think it's worth the time to compile these different versions 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 :)