You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 13, 2022. It is now read-only.
Jan Stephan edited this page Dec 9, 2016
·
2 revisions
Philosophy
In some cases it is not desirable to frequently allocate and free memory, especially when the allocated objects are of the same size. In order to prevent the malloc/free overhead for these objects GLADOS offers memory pools for 1D, 2D and 3D cases.
Usage
To use GLADOS' memory pool the user needs to specify three types via template parameters:
the type of the allocated memory
the memory layout (1D, 2D or 3D)
an allocator conforming to the abovementioned points
Example for GLADOS' CUDA device allocator:
using device_allocator = glados::cuda::device_allocator<float, memory_layout::pointer_2D>;
using pool_allocator = glados::pool_allocator<float, memory_layout::pointer_2D, device_allocator>;
auto alloc = pool_allocator{};
// optionally specify a limitauto limit = std::size_t{100};
auto alloc_limit = pool_allocator{limit};
To allocate objects of the same size either call allocate (for a raw pointer) or allocate_smart (for an unique_ptr-like object):
// allocate raw 2D pointerauto raw = alloc.allocate(800, 600);
// allocate smart 2D pointerauto smart = alloc.allocate_smart(800, 600);
// return raw 2D pointer to pool
alloc.deallocate(raw);
// no need to deallocate smart 2D pointer -- let RAII handle this
To release the managed memory, call release:
// calls the actual allocators memory free functions
alloc.release();
Note that the managed memory is NOT automatically freed upon memory_pool's destruction - the user MUST call release once the pool is no longer needed.
Important notes
GLADOS' pool_allocator uses fixed-size pointers. This means that the first call to allocate or allocate_smart will set the dimensions for all succeeding calls as well; the size parameters will therefore be ignored. If you want to reuse the pool for other dimensions later you need to release the managed memory first by calling release; this will automatically reset the size limit.