SharedAllocator is simple allocator that allocates memory inside one shared library and can be used to make it safe to share STL containers between several shared libraries.
OTHER License
SharedAllocator is simple allocator that allocates memory inside one shared library and can be used to make it safe
to share STL containers between several shared libraries.
SharedAllocator interface is similar to std::allocator
interface
so std::allocator
can be easily replaced by salloc::shared_allocator
(or by other salloc::
allocators).
SharedAllocator is using features of C++11 standard, so you have to use C++11 compatible compiler.
include/shared_allocator/*.*
to your include directoryinclude/third_party/shared_allocator
or just include/shared_allocator
).source/*.*
to your sources directory (for example, source/shared_allocator
).source/shared_allocator/CMakeLists.txt
(from step 2) into your main CMakeLists.txt: add_subdirectory(source/shared_allocator)
include_directories(include/third_party)
#include "shared_allocator/shared_allocator.hpp"
.salloc::shared_allocator<T>
shared_allocate
function and so on): target_link_libraries(${PROJECT_NAME} shared_allocator)
#include "shared_allocator/shared_allocator.hpp"
#include <vector>
int main()
{
// This vector can be safely shared among several shared libraries.
std::vector<int, salloc::shared_allocator<int> > shared_vector;
shared_vector.reserve(100);
for (int i = 0; i < 100; ++i)
{
shared_vector.push_back(i);
}
return 0;
}
shared_allocate
shared_deallocate
. All instances of this allocator will allocate and deallocate memory inside one heap.std::list
, std::set
, std::map
). It is not so good for std::vector
because it needs memory allocations ofsalloc::cached_allocator
instead of salloc::shared_allocator
std::vector
.salloc::cached_allocator
but it have an individual cache for each size of memory bufferSharedAllocator is licensed under terms of MIT license.