CoreAllocatorAdapter class

CoreAllocatorAdapter.

Implements the EASTL allocator interface. Allocates memory from an instance of ICoreAllocator or another class with an equivalent interface. ICoreAllocator is a pure-virtual memory allocation interface used by a number of EA games and shared libraries. It's completely unrelated to EASTL, but it's prevalent enough that it's useful for EASTL to have a built-in adapter for this interface. ICoreAllocator is declared in the ICoreAllocator.h header, but CoreAllocatorAdapter can work with any equivalent interface, as defined below.

Expected interface: enum AllocFlags { kFlagTempMemory = 0, kFlagPermMemory = 1 };

struct CoreAllocator { void* Alloc(size_t size, const char* name, unsigned int allocFlags); void* Alloc(size_t size, const char* name, unsigned int allocFlags, // Not required unless you are working with types that require custom alignment. unsigned int align, unsigned int alignOffset = 0); void Free(void* block, size_t size = 0); static CoreAllocator* GetDefaultAllocator(); };

Example usage: include <coreallocator/icoreallocator_interface.h> typedef EA::Allocator::CoreAllocatorAdapter<EASTLTestCoreAllocator> Adapter; eastl::list<Widget, Adapter> widgetList(Adapter("UI/WidgetList", pSomeCoreAllocator)); widgetList.push_back(Widget());

Example usage: include <MyEquivalentCoreAllocatorInterface.h> eastl::list<Widget, CoreAllocatorAdapter<MyCoreAllocatorInterface> > widgetList; widgetList.push_back(Widget());

Example usage: include <coreallocator/icoreallocator_interface.h> typedef EA::Allocator::CoreAllocatorAdapter<EASTLTestCoreAllocator> Adapter; typedef eastl::list<Widget, Adapter> WidgetList; CoreAllocatorFixed<WidgetList::node_type> widgetCoreAllocator(pFixedAllocatorForWidgetListValueType); // CoreAllocatorFixed is a hypothetical implementation of the ICoreAllocator interface. WidgetList widgetList(Adapter("UI/WidgetList", &widgetCoreAllocator)); // Note that the widgetCoreAllocator is declared before and thus destroyed after the widget list.

Constructors, destructors, conversion operators

CoreAllocatorAdapter(const char* pName = EASTL_NAME_VAL(EASTL_ALLOCATOR_DEFAULT_NAME), AllocatorType* pAllocator = EASTL_CORE_ALLOCATOR_ADAPTER_GET_DEFAULT_CORE_ALLOCATOR())
CoreAllocatorAdapter(const char* pName, AllocatorType* pAllocator, int flags)
CoreAllocatorAdapter(const CoreAllocatorAdapter& x)
CoreAllocatorAdapter(const CoreAllocatorAdapter& x, const char* pName)

Public functions

auto operator=(const CoreAllocatorAdapter& x) -> CoreAllocatorAdapter&
auto allocate(size_t n, int flags = 0) -> void*
auto allocate(size_t n, size_t alignment, size_t offset, int flags = 0) -> void*
auto deallocate(void* p, size_t n) -> void
auto get_allocator() const -> AllocatorType*
auto set_allocator(AllocatorType* pAllocator) -> void
auto get_flags() const -> int
auto set_flags(int flags) -> void
auto get_name() const -> const char*
auto set_name(const char* pName) -> void

Public variables

AllocatorType* mpCoreAllocator
int mnFlags