Raven Engine v0.1
Loading...
Searching...
No Matches
Raven::MalevolentAllocator Class Reference

Fixed-size chunk pool allocator. More...

#include <MalevolentAllocator.h>

Public Member Functions

 MalevolentAllocator (usize chunkSize, usize chunkCount)
 Constructs the allocator with specified chunk size and count.
 ~MalevolentAllocator () noexcept
 Releases all allocated memory.
void * Allocate ()
 Allocates one chunk from the pool.
void Deallocate (void *ptr)
 Returns a previously allocated chunk to the pool.

Detailed Description

Fixed-size chunk pool allocator.

Pre-allocates a block of memory divided into chunkCount chunks of chunkSize bytes. Maintains a free list for O(1) Allocate and Deallocate operations.

Implements a simple pool allocator that pre-allocates a contiguous block of memory divided into equal-sized chunks. Allocation and deallocation operate in constant time via a free list. This allocator is useful for fast, repetitive allocations of objects with identical size requirements.

Constructor & Destructor Documentation

◆ MalevolentAllocator()

Raven::MalevolentAllocator::MalevolentAllocator ( usize chunkSize,
usize chunkCount )

Constructs the allocator with specified chunk size and count.

Parameters
chunkSizeSize in bytes of each chunk.
chunkCountNumber of chunks to allocate in the pool.

◆ ~MalevolentAllocator()

Raven::MalevolentAllocator::~MalevolentAllocator ( )
noexcept

Releases all allocated memory.

Member Function Documentation

◆ Allocate()

void * Raven::MalevolentAllocator::Allocate ( )

Allocates one chunk from the pool.

Returns
Pointer to the allocated memory chunk, or nullptr if pool is exhausted.

◆ Deallocate()

void Raven::MalevolentAllocator::Deallocate ( void * ptr)

Returns a previously allocated chunk to the pool.

Parameters
ptrPointer to the memory chunk to deallocate.

The documentation for this class was generated from the following files: