ezEngine Release 26.3
Loading...
Searching...
No Matches
ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset > Class Template Reference

Stack-based linear allocator that allocates memory sequentially. More...

#include <LinearAllocator.h>

Inheritance diagram for ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >:

Public Member Functions

 ezLinearAllocator (ezStringView sName, ezAllocator *pParent)
 
virtual void * Allocate (size_t uiSize, size_t uiAlign, ezMemoryUtils::DestructorFunction destructorFunc) override
 Interface, do not use this directly, always use the new/delete macros below.
 
virtual void Deallocate (void *pPtr) override
 Deallocates memory previously allocated by this allocator.
 
void Reset ()
 Resets the allocator, freeing all memory and calling destructors.
 
- Public Member Functions inherited from ezAllocatorWithPolicy< AllocationPolicy, TrackingMode >
 ezAllocatorWithPolicy (ezStringView sName, ezAllocator *pParent=nullptr)
 
- Public Member Functions inherited from ezInternal::ezAllocatorMixinReallocate< AllocationPolicy, TrackingMode, HasReallocate >
 ezAllocatorMixinReallocate (ezStringView sName, ezAllocator *pParent)
 
- Public Member Functions inherited from ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >
 ezAllocatorImpl (ezStringView sName, ezAllocator *pParent)
 
virtual size_t AllocatedSize (const void *pPtr) override
 Returns the number of bytes allocated at this address.
 
virtual ezAllocatorId GetId () const override
 
virtual Stats GetStats () const override
 
ezAllocatorGetParent () const
 
- Public Member Functions inherited from ezAllocator
virtual void * Reallocate (void *pPtr, size_t uiCurrentSize, size_t uiNewSize, size_t uiAlign)
 Reallocates memory, potentially moving the data to a new location.
 

Additional Inherited Members

- Protected Attributes inherited from ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >
AllocationPolicy m_allocator
 
ezAllocatorId m_Id
 
ezThreadID m_ThreadID
 

Detailed Description

template<ezAllocatorTrackingMode TrackingMode = ezAllocatorTrackingMode::Default, bool OverwriteMemoryOnReset = false>
class ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >

Stack-based linear allocator that allocates memory sequentially.

This allocator allocates memory by simply advancing a pointer within a pre-allocated buffer. Individual deallocations are not supported - the entire allocator must be reset at once. Very efficient for temporary allocations that follow a stack-like pattern.

Template parameters:

  • TrackingMode: Controls allocation tracking and debugging features
  • OverwriteMemoryOnReset: If true, fills memory with debug pattern on reset (debug builds only)

Performance characteristics:

  • Allocation: O(1) - just pointer arithmetic
  • Deallocation: Not supported individually
  • Reset: O(1) - just resets pointer
  • Memory overhead: Minimal

Use when:

  • Temporary allocations with predictable lifetime
  • Stack-like allocation pattern
  • High allocation frequency (parsing, temporary buffers)
  • Frame-based or scope-based memory management

Member Function Documentation

◆ Allocate()

template<ezAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
void * ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >::Allocate ( size_t  uiSize,
size_t  uiAlign,
ezMemoryUtils::DestructorFunction  destructorFunc 
)
overridevirtual

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).

Reimplemented from ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >.

◆ Deallocate()

template<ezAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
void ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >::Deallocate ( void *  pPtr)
overridevirtual

Deallocates memory previously allocated by this allocator.

The pointer must have been returned by a previous call to Allocate() on this allocator instance. Passing nullptr is safe and will be ignored.

Reimplemented from ezInternal::ezAllocatorImpl< AllocationPolicy, TrackingMode >.

◆ Reset()

template<ezAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
EZ_MSVC_ANALYSIS_WARNING_PUSH void ezLinearAllocator< TrackingMode, OverwriteMemoryOnReset >::Reset ( )

Resets the allocator, freeing all memory and calling destructors.

This resets the allocation pointer to the beginning and calls destructors for all objects that were allocated with destructor functions. After reset, all previously allocated pointers become invalid and must not be used.


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