ezEngine Release 25.08
Loading...
Searching...
No Matches
ezLocalAllocatorWrapper Struct Reference

Helper function to facilitate setting the allocator on member containers of a class Allocators can be either template arguments or a ctor parameter. Using the ctor parameter requires the class ctor to reference each member container in the initialization list. This can be very tedious. On the other hand, the template variant only support template parameter so you can't simply pass in a member allocator. This class solves this problem provided the following rules are followed: More...

#include <AllocatorWrapper.h>

Public Member Functions

 ezLocalAllocatorWrapper (ezAllocator *pAllocator)
 
void Reset ()
 

Static Public Member Functions

static ezAllocatorGetAllocator ()
 

Detailed Description

Helper function to facilitate setting the allocator on member containers of a class Allocators can be either template arguments or a ctor parameter. Using the ctor parameter requires the class ctor to reference each member container in the initialization list. This can be very tedious. On the other hand, the template variant only support template parameter so you can't simply pass in a member allocator. This class solves this problem provided the following rules are followed:

  1. The ezAllocator must be the declared at the earliest in the class, before any container.
  2. The ezLocalAllocatorWrapper should be declared right afterwards.
  3. Any container needs to be declared below these two and must include the ezLocalAllocatorWrapper as a template argument to the allocator.
  4. In the ctor initializer list, init the ezAllocator first, then the ezLocalAllocatorWrapper. With this approach all containers can be omitted.
    class MyClass
    {
    ezAllocator m_SpecialAlloc;
    MyClass()
    : m_SpecialAlloc("MySpecialAlloc")
    , m_Wrapper(&m_SpecialAlloc)
    {
    }
    }
    Base class for all memory allocators.
    Definition Allocator.h:23
    Definition DynamicArray.h:81
    Helper function to facilitate setting the allocator on member containers of a class Allocators can be...
    Definition AllocatorWrapper.h:52

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