XII Release 0.1.0
Loading...
Searching...
No Matches
xiiLinearAllocator< TrackingMode, OverwriteMemoryOnReset > Class Template Reference

Copyright (c) Theophilus Eriata. All Rights Reserved. More...

#include <LinearAllocator.h>

Inheritance diagram for xiiLinearAllocator< TrackingMode, OverwriteMemoryOnReset >:
[legend]

Public Member Functions

 xiiLinearAllocator (xiiStringView sName, xiiAllocator *pParent, xiiUInt32 uiInitialSize)
 Copyright (c) Theophilus Eriata. All Rights Reserved.
virtual void * Allocate (size_t uiSize, size_t uiAlign, xiiMemoryUtils::DestructorFunction destructorFunc) override
virtual void Deallocate (void *pPtr) override
void Reset ()
Public Member Functions inherited from xiiAllocatorWithPolicy< xiiAllocationPolicyLinear< false >, xiiAllocatorTrackingMode::Default >
 xiiAllocatorWithPolicy (xiiStringView sName, xiiAllocator *pParent=nullptr)
Public Member Functions inherited from xiiInternal::xiiAllocatorMixinReallocate< xiiAllocationPolicyLinear< false >, TrackingMode, xiiHasReallocate< xiiAllocationPolicyLinear< false >, void *(xiiAllocationPolicyLinear< false >::*)(void *, size_t, size_t, size_t)>::value >
 xiiAllocatorMixinReallocate (xiiStringView sName, xiiAllocator *pParent)
Public Member Functions inherited from xiiInternal::xiiAllocatorImpl< xiiAllocationPolicyLinear< false >, TrackingMode >
 xiiAllocatorImpl (xiiStringView sName, xiiAllocator *pParent)
virtual size_t AllocatedSize (const void *pPtr) override
virtual xiiAllocatorId GetId () const override
virtual Stats GetStats () const override
xiiAllocator * GetParent () const
Public Member Functions inherited from xiiAllocator
 xiiAllocator ()
 Copyright (c) Theophilus Eriata. All Rights Reserved.
virtual void * Reallocate (void *pPtr, size_t uiCurrentSize, size_t uiNewSize, size_t uiAlign)
 Copyright (c) Theophilus Eriata. All Rights Reserved.

Additional Inherited Members

Protected Attributes inherited from xiiInternal::xiiAllocatorImpl< xiiAllocationPolicyLinear< false >, TrackingMode >
xiiAllocationPolicyLinear< false > m_Allocator
xiiAllocatorId m_Id
xiiThreadID m_ThreadID

Detailed Description

template<xiiAllocatorTrackingMode TrackingMode = xiiAllocatorTrackingMode::Default, bool OverwriteMemoryOnReset = false>
class xiiLinearAllocator< TrackingMode, OverwriteMemoryOnReset >

Copyright (c) Theophilus Eriata. All Rights Reserved.

Linear allocator that allocates memory sequentially.

This allocator allocates memory by simply advancing a pointer within pre-allocated chunks. Individual deallocations are not supported - the entire allocator must be reset at once. Very efficient for short lived allocations.

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<xiiAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
void * xiiLinearAllocator< TrackingMode, OverwriteMemoryOnReset >::Allocate ( size_t uiSize,
size_t uiAlign,
xiiMemoryUtils::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 xiiInternal::xiiAllocatorImpl< xiiAllocationPolicyLinear< false >, TrackingMode >.

◆ Deallocate()

template<xiiAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
void xiiLinearAllocator< 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 xiiInternal::xiiAllocatorImpl< xiiAllocationPolicyLinear< false >, TrackingMode >.

◆ Reset()

template<xiiAllocatorTrackingMode TrackingMode, bool OverwriteMemoryOnReset>
XII_MSVC_ANALYSIS_WARNING_PUSH void xiiLinearAllocator< 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: