Documentation of memory
The C++ STL allocator model has various flaws. For example, they are fixed to a certain type, because they are almost necessarily required to be templates. So you can't easily share a single allocator for multiple types. In addition, you can only get a copy from the containers and not the original allocator object. At least with C++11 they are allowed to be stateful and so can be made object not instance based. But still, the model has many flaws. Over the course of the years many solutions have been proposed. for example EASTL. This library is another. But instead of trying to change the STL, it works with the current implementation.
New allocator concepts:
RawAllocatorthat is similar to an
Allocatorbut easier to use and write
BlockAllocatorthat is an allocator for huge memory blocks
- virtual memory allocators
- allocator using a static memory block located on the stack
- memory stack,
- different memory pools
- a portable, improved
alloca()in the form of
- facilities for joint memory allocations: share a big memory block for the object and all dynamic memory allocations for its members
Adapters, wrappers and storage classes:
- incredible powerful
std_allocatorto make a
- adapters for the memory resource TS
allocator_deleterclasses for smart pointers
- (optionally type-erased)
allocator_referenceand other storage classes
- memory tracking wrapper
- container node size debuggers that obtain information about the node size of an STL container at compile-time to specify node sizes for pools
- debugging options for leak checking, double-free checks or buffer overflows
- customizable error handling routines that can work with exceptions disabled
- everything except the STL adapters works on a freestanding environment
example/ for more.
This library can be used as CMake subdirectory. It is tested on GCC 4.8-5.0, Clang 3.5 and Visual Studio 2013. Newer versions should work too.
- Fetch it, e.g. using git submodules
git submodule add https://github.com/foonathan/memory ext/memoryand
git submodule update --init --recursive.
add_subdirectory(ext/memory)or whatever your local path is to make it available in CMake.
- Simply call
target_link_libraries(your_target PUBLIC foonathan_memory)to link this library and setups the include search path and compilation options.
Note: If during CMake you see an error message that compatibility is not on the newest version, run
git submodule update --recursive --remote to force the compatiblity submodule of memory to update to the latest version.
You can also install the library:
cmake -DCMAKE_BUILD_TYPE="buildtype" -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF -DFOONATHAN_MEMORY_BUILD_TESTS=OFF .inside the library sources.
cmake --build . -- installto install the library under
- Repeat 1 and 2 for each build type/configuration you want to have (like
Releaseor custom names).
To use an installed library:
find_package(foonathan_memory major.minor REQUIRED)to find the library.
target_link_libraries(your_target PUBLIC foonathan_memory)to link to the library and setup all required options.
See http://foonathan.github.io/doc/memory/md_doc_installation.html for a detailed guide.
Full documentation can be found at http://foonathan.github.io/doc/memory.
A tutorial is also available at http://foonathan.github.io/doc/memory/md_doc_tutorial.html.
Below is the interface required for a
RawAllocator, everything optional is marked:
RawAllocator only needs to be moveable, all
Allocator classes are
RawAllocators too. Classes not providing the interface can specialize the
allocator_traits, read more about writing allocators here or about the technical details of the concept here.
Generated by 1.8.12