MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Memory Allocation

Allocation related methods and classes. More...

Classes

struct  mtcore::Allocator
 Represents a memory allocator Exact behavior depends on the underlying VTable used Should use the a_* methods for working with an allocator. More...
 
struct  mtcore::MallocAllocator
 State variable for malloc-based allocator. More...
 
struct  mtcore::ThreadLocalDebugAllocator
 State variable for thread local debug allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::ThreadLocalFixedBufferAllocator
 State variable for thread local fixed buffer allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::ThreadLocalFixedArenaAllocator
 State variable for thread local fixed arena allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::ThreadLocalDynamicArenaAllocator
 State variable for thread local dynamic arena allocator Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::thread::DynamicArenaAllocator
 Allocator state object for shared dynamic arena allocation Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::thread::FixedArenaAllocator
 Allocator state object for shared fixed arena allocation Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::thread::FixedBufferAllocator
 Allocator state object for shared fixed buffer allocation Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 
struct  mtcore::thread::DebugAllocator
 Allocator state object for shared debug allocation Must live longer (and at the same memory address) than all allocators returned by allocator() More...
 

Functions

MallocAllocator mtcore::malloc_alloc () noexcept
 Creates a memory allocator using the standard's malloc under the hood Does no memory tracking Ideal for production/release/high performance.
 
ThreadLocalDebugAllocator mtcore::debug_alloc_thread_local () noexcept
 NOT THREAD SAFE!
 
ThreadLocalFixedBufferAllocator mtcore::fixed_buff_thread_local (Slice< u8 > bytes) noexcept
 NOT THREAD SAFE!
 
ThreadLocalFixedArenaAllocator mtcore::fixed_arena_thread_local (Slice< u8 > bytes) noexcept
 NOT THREAD SAFE!
 
ThreadLocalDynamicArenaAllocator mtcore::dynamic_arena_thread_local (Allocator *root, size_t elementSizeHint, size_t elementCountHint) noexcept
 NOT THREAD SAFE!
 
DynamicArenaAllocator mtcore::thread::dynamic_arena (Allocator *root, size_t elementSizeHint, size_t elementCountHint) noexcept
 Creates a dynamically growing arena allocator This arena allocator will grow if it runs out of space The allocator will clean all pages on deinit, and reallocate them again when the next allocation happens It does iterate through all pages, so it's \(O(p)\) to allocate Use maxElementHint (max element size) and maxCountHint (max number of elements per page) to hint at page size.
 
FixedArenaAllocator mtcore::thread::fixed_arena (Slice< u8 > bytes) noexcept
 Creates basic arena allocator which just pushes more state onto the end Calling deinit will simply reset the stack pointer.
 
FixedBufferAllocator mtcore::thread::fixed_buff (Slice< u8 > bytes) noexcept
 Creates an allocator that works on a fixed buffer of bytes.
 
DebugAllocator mtcore::thread::debug_alloc () noexcept
 Creates a memory allocator using the standard's malloc under the hood This allocator will do basic tracking of memory allocations Once all instances of std_alloc are de-initialized, it will then check to see if any memory is being leakd.
 

Detailed Description

Allocation related methods and classes.

Function Documentation

◆ debug_alloc()

DebugAllocator mtcore::thread::debug_alloc ( )
noexcept

Creates a memory allocator using the standard's malloc under the hood This allocator will do basic tracking of memory allocations Once all instances of std_alloc are de-initialized, it will then check to see if any memory is being leakd.

If memory would be leaked, it will return an error in the deinit method.

This allocator assumes that memory maybe passed between instances of std_alloc_global so it will only do a memory check once ALL std_alloc_global allocators are deinitialized, not just when one is.

RECOMMENDED USAGE: It is recommended to only have one instance of this allocator globally, and then to pass that allocator everywhere

Returns
Allocator that uses malloc under the hood
Here is the call graph for this function:
Here is the caller graph for this function:

◆ debug_alloc_thread_local()

ThreadLocalDebugAllocator mtcore::debug_alloc_thread_local ( )
noexcept

NOT THREAD SAFE!

Creates a debug memory allocator that does memory leak detection. This allocator will do basic tracking of memory allocations When deinitialized, it will then check it's state to see if any memory is leaked. If memory is leaked, it will return an error in the deinit method.

RECOMMENDED USAGE: It is recommended to only have one instance of this allocator per thread, and then to pass that allocator everywhere

Returns
Allocator that uses malloc under the hood and does memory tracking
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamic_arena()

DynamicArenaAllocator mtcore::thread::dynamic_arena ( Allocator * root,
size_t elementSizeHint,
size_t elementCountHint )
noexcept

Creates a dynamically growing arena allocator This arena allocator will grow if it runs out of space The allocator will clean all pages on deinit, and reallocate them again when the next allocation happens It does iterate through all pages, so it's \(O(p)\) to allocate Use maxElementHint (max element size) and maxCountHint (max number of elements per page) to hint at page size.

Parameters
rootPointer to base allocator to use (must be in memory address stable)
elementSizeHintHint for most likely size of elements. Used for initial allocation
elementCountHinthint for most likely count of elements. Used for initial allocation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamic_arena_thread_local()

ThreadLocalDynamicArenaAllocator mtcore::dynamic_arena_thread_local ( Allocator * root,
size_t elementSizeHint,
size_t elementCountHint )
noexcept

NOT THREAD SAFE!

Creates a dynamically growing arena allocator This arena allocator will grow if it runs out of space The allocator will clean all pages on deinit, and reallocate them again when the next allocation happens It does iterate through all pages, so it's \(O(p)\) to allocate Use maxElementHint (max element size) and maxCountHint (max number of elements per page) to hint at page size

Parameters
rootPointer to base allocator to use (must be in memory address stable)
elementSizeHintHint for most likely size of elements. Used for initial allocation
elementCountHinthint for most likely count of elements. Used for initial allocation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fixed_arena()

FixedArenaAllocator mtcore::thread::fixed_arena ( Slice< u8 > bytes)
noexcept

Creates basic arena allocator which just pushes more state onto the end Calling deinit will simply reset the stack pointer.

Safe to reuse after deinit No reallocation supported, free is a noop, no compaction

Uses a fixed size buffer for allocations. Will fail to allocate once buffer is exhausted

Parameters
bytesSlice to section of memory that will be used by the allocator. Must be valid for allocator lifetime
Returns
Arena allocator that is limited to a fixed buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fixed_arena_thread_local()

ThreadLocalFixedArenaAllocator mtcore::fixed_arena_thread_local ( Slice< u8 > bytes)
noexcept

NOT THREAD SAFE!

Creates basic arena allocator which just pushes more state onto the end Calling deinit will simply reset the stack pointer. Safe to reuse after deinit No reallocation supported, free is a noop, no compaction

Uses a fixed size buffer for allocations. Will fail to allocate once buffer is exhausted

Parameters
bytesSlice to section of memory that will be used by the allocator. Must be valid for allocator lifetime
Returns
Arena allocator that is limited to a fixed buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fixed_buff()

FixedBufferAllocator mtcore::thread::fixed_buff ( Slice< u8 > bytes)
noexcept

Creates an allocator that works on a fixed buffer of bytes.

Uses same implementation as

See also
fixed_buff_thread_local
Parameters
bytesSlice to section of memory that will be used by the allocator. Must be valid for allocator lifetime
Returns
Allocator that is limited to a fixed buffer
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fixed_buff_thread_local()

ThreadLocalFixedBufferAllocator mtcore::fixed_buff_thread_local ( Slice< u8 > bytes)
noexcept

NOT THREAD SAFE!

Creates an allocator that works on a fixed buffer of bytes. Currently, this uses a simple free list with very basic compaction. May revisit implementation in the future

Parameters
bytesSlice to section of memory that will be used by the allocator. Must be valid for allocator lifetime
Returns
Allocator that is limited to a fixed buffer. Not thread safe
Here is the call graph for this function:
Here is the caller graph for this function:

◆ malloc_alloc()

MallocAllocator mtcore::malloc_alloc ( )
noexcept

Creates a memory allocator using the standard's malloc under the hood Does no memory tracking Ideal for production/release/high performance.

Returns
Allocator that uses malloc under the hood
Here is the call graph for this function:
Here is the caller graph for this function: