I have been learning C++, and have come across the topics of custom memory allocators. I have understood that by designing an allocator and using this allocator with standard library containers, we can avoid heap allocation. Also, it seems that we can avoid memory fragmentation. This is achieved in part by using the placement new and placement delete operators.
Is the design of a custom memory allocator also possible in C, such that we can control memory allocation and avoid fragmentation ? If it is possible, does C++ simply offer this capability with higher levels of abstraction ?
Both C and C++ are low-magic languages. C especially allocates little memory behind your back. It might do so for vararg functions, for instance, but almost every normal datastructure is allocated explicitly by you, the programmer. If you call
malloc, the default heap is used. If you call something else, something else is used.