25 #include <mach/vm_statistics.h> 70 std::vector<void *> crt_malloc_list;
94 #pragma warning(push) // Xcode thinks thinks a 0-sized entity in a class is OK, but Visual Studio kicks up a fuss (but does it anyway). 95 #pragma warning(disable : 4200) 147 return ::malloc((
size_t)size);
188 allocator_pool(
size_t block_size_for_allocation = default_allocation_size);
217 return (
used == other->size()) && (
allocated == other->capacity()) && (current_chunk.load() == other->current_chunk.load());
243 return (
used != other->size()) || (
allocated != other->capacity()) || (current_chunk.load() != other->current_chunk.load());
272 virtual void rewind(
void);
virtual bool operator!=(const allocator &with)
Compare for inequlity two objects of this class type.
Definition: allocator_pool.h:235
uint8_t * chunk_end
Pointer to the end of the current chunk's large allocation (used to check for overflow).
Definition: allocator_pool.h:90
Details of an individual large-allocation unit.
Definition: allocator_pool.h:86
std::atomic< size_t > allocated
The number of bytes this object has allocated.
Definition: allocator.h:43
size_t block_size
The size (in bytes) of the large-allocations this object will make.
Definition: allocator_pool.h:67
chunk * add_chunk(size_t bytes)
Get memory from the C++ free store (or the Operating System) and add it to the linked list of large-a...
Definition: allocator_pool.cpp:49
static const size_t default_allocation_size
Allocations from the C++ free-store are this size.
Definition: allocator_pool.h:64
std::atomic< uint8_t * > chunk_at
Pointer to the next byte that can be allocated (within the current chunk).
Definition: allocator_pool.h:89
virtual void * malloc(size_t bytes, size_t alignment=alignment_boundary)
Allocate a small chunk of memory from the internal block and return a pointer to the caller...
Definition: allocator_pool.cpp:90
static void unittest(void)
Unit test this class.
Definition: allocator_pool.cpp:219
virtual bool operator==(const allocator &with)
Compare for equality two objects of this class type.
Definition: allocator_pool.h:209
chunk * next_chunk
Pointer to the previous large allocation (i.e. chunk).
Definition: allocator_pool.h:91
virtual void rewind(void)
Throw away (without calling delete) all objects allocated in the memory space of this object...
Definition: allocator_pool.cpp:167
virtual ~allocator_pool()
Destructor.
Definition: allocator_pool.cpp:38
std::atomic< chunk * > current_chunk
Pointer to the top of the chunk list (of large allocations).
Definition: allocator_pool.h:104
Simple block-allocator that internally allocates a large chunk then allocates smaller blocks from thi...
Definition: allocator_pool.h:61
Virtual base class for C style allocators.
Definition: allocator.h:33
static void unittest_thread(dynamic_array< uint8_t *> &answer, allocator_pool &memory, uint8_t bytes)
Unit test this class - thread manager.
Definition: allocator_pool.cpp:199
uint8_t data[]
The data in this large allocation that is available for re-distribution.
Definition: allocator_pool.h:97
std::atomic< size_t > used
The number of bytes this object has passed back to the caller.
Definition: allocator.h:42
size_t chunk_size
The size of this chunk.
Definition: allocator_pool.h:92
void dealloc(void *buffer) const
Hand back to the C++ free store (or Operating system) a chunk of memory that has previously been allo...
Definition: allocator_pool.h:159
size_t size(void) const
Return the number of bytes of memory this object has handed back to callers.
Definition: allocator.h:128
Thread-safe grow-only dynamic array using the thread-safe allocator.
Definition: allocator_pool.h:32
void * alloc(size_t size) const
Allocate more memory from the C++ free-store.
Definition: allocator_pool.h:129
Base class for different allocators.
Definition: compress_integer_elias_delta_simd.c:23
static constexpr size_t alignment_boundary
Elsewhere don't bother with alignment (align on byte boundaries)
Definition: allocator.h:39