How do I free memory in C?

You have to free() the allocated memory in exact reverse order of how it was allocated using malloc(). Note that You should free the memory only after you are done with your usage of the allocated pointers. memory allocation for 1D arrays: buffer = malloc(num_items*sizeof(double)); memory deallocation for 1D arrays: free(buffer); memory allocation for 2D … Read more

Multithreaded Memory Allocators for C/C++

I’ve used tcmalloc and read about Hoard. Both have similar implementations and both achieve roughly linear performance scaling with respect to the number of threads/CPUs (according to the graphs on their respective sites). So: if performance is really that incredibly crucial, then do performance/load testing. Otherwise, just roll a dice and pick one of the … Read more

Is circumventing a class’ constructor legal or does it result in undefined behaviour?

It is legal now, and retroactively since C++98! Indeed the C++ specification wording till C++20 was defining an object as (e.g. C++17 wording, [intro.object]): The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. An object is created by a definition (6.1), by a new-expression (8.5.2.4), when implicitly changing the active … Read more