ezEngine Release 26.3
Loading...
Searching...
No Matches
ezAllocator Class Referenceabstract

Base class for all memory allocators. More...

#include <Allocator.h>

Inheritance diagram for ezAllocator:

Classes

struct  Stats
 

Public Member Functions

virtual void * Allocate (size_t uiSize, size_t uiAlign, ezMemoryUtils::DestructorFunction destructorFunc=nullptr)=0
 Interface, do not use this directly, always use the new/delete macros below.
 
virtual void Deallocate (void *pPtr)=0
 Deallocates memory previously allocated by this allocator.
 
virtual void * Reallocate (void *pPtr, size_t uiCurrentSize, size_t uiNewSize, size_t uiAlign)
 Reallocates memory, potentially moving the data to a new location.
 
virtual size_t AllocatedSize (const void *pPtr)=0
 Returns the number of bytes allocated at this address.
 
virtual ezAllocatorId GetId () const =0
 
virtual Stats GetStats () const =0
 

Detailed Description

Base class for all memory allocators.

This abstract base class defines the interface for all allocators in ezEngine. Allocators are responsible for memory management and can implement different allocation strategies (heap, linear, frame, etc.).

Key concepts:

  • All allocators provide aligned memory allocation
  • Optional tracking of allocation statistics and debugging information
  • Virtual interface allows swapping allocator implementations
  • Thread safety depends on specific allocator implementation

Usage:

  • Use EZ_NEW/EZ_DELETE macros instead of calling Allocate/Deallocate directly
  • Different allocator types optimize for different usage patterns
  • Always pair allocations with deallocations using the same allocator instance

Member Function Documentation

◆ Allocate()

virtual void * ezAllocator::Allocate ( size_t  uiSize,
size_t  uiAlign,
ezMemoryUtils::DestructorFunction  destructorFunc = nullptr 
)
pure virtual

Interface, do not use this directly, always use the new/delete macros below.

Allocates aligned memory of the specified size. The destructorFunc parameter is used for automatic cleanup when the allocator is reset or destroyed (mainly used by linear allocators).

Implemented in ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >, ezLinearAllocator< ezAllocatorTrackingMode::Basics >, ezLinearAllocator< ezAllocatorTrackingMode::Nothing >, ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >, ezInternal::ezAllocatorImpl< ezAllocPolicyHeap, TrackingMode >, ezInternal::ezAllocatorImpl< ezAllocPolicyLinear< false >, TrackingMode >, and ezInternal::ezAllocatorImpl< ezAllocPolicyProxy, TrackingMode >.

◆ AllocatedSize()

virtual size_t ezAllocator::AllocatedSize ( const void *  pPtr)
pure virtual

Returns the number of bytes allocated at this address.

This information is only available if allocation tracking is enabled (see ezAllocatorTrackingMode and EZ_ALLOC_TRACKING_DEFAULT). Returns 0 when tracking is disabled or for invalid pointers. Primarily used for debugging and memory analysis.

Implemented in ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >, ezInternal::ezAllocatorImpl< ezAllocPolicyHeap, TrackingMode >, ezInternal::ezAllocatorImpl< ezAllocPolicyLinear< false >, TrackingMode >, and ezInternal::ezAllocatorImpl< ezAllocPolicyProxy, TrackingMode >.

◆ Deallocate()

virtual void ezAllocator::Deallocate ( void *  pPtr)
pure virtual

◆ Reallocate()

void * ezAllocator::Reallocate ( void *  pPtr,
size_t  uiCurrentSize,
size_t  uiNewSize,
size_t  uiAlign 
)
virtual

Reallocates memory, potentially moving the data to a new location.

Default implementation allocates new memory, copies old data, and deallocates the old memory. Some allocators may provide more efficient implementations.

Reimplemented in ezInternal::ezAllocatorMixinReallocate< AllocationPolicy, TrackingMode, true >.


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