XII Release 0.1.0
Loading...
Searching...
No Matches
xiiInstanceDataAllocator Class Reference

#include <InstanceDataAllocator.h>

Public Member Functions

xiiUInt32 AddDesc (const xiiInstanceDataDesc &desc)
 Adds the given desc to internal list of data that needs to be allocated and returns the byte offset.
void ClearDescs ()
 Resets all internal state.
void Construct (xiiByteBlobPtr blobPtr) const
 Constructs the instance data objects, within the pre-allocated memory block.
void Destruct (xiiByteBlobPtr blobPtr) const
 Destructs the instance data objects.
xiiBlob AllocateAndConstruct () const
 Allocates memory and constructs the instance data objects inside it. The returned xiiBlob must be stored somewhere.
void DestructAndDeallocate (xiiBlob &ref_blob) const
 Destructs and deallocates the instance data objects and the given memory block.
xiiUInt32 GetTotalDataSize () const
 The total size in bytes taken up by all instance data objects that were added.

Static Public Member Functions

static XII_ALWAYS_INLINE void * GetInstanceData (const xiiByteBlobPtr &blobPtr, xiiUInt32 uiOffset)
 Retrieves a void pointer to the instance data within the given blob at the given offset, or nullptr if the offset is invalid.

Detailed Description

Manages complex multi-type instance data allocation with proper construction and destruction.

This allocator is designed for systems that need to allocate heterogeneous data structures in a single memory block, such as VM instances, state machines, or script execution contexts. It calculates proper alignments for mixed data types and handles construction/destruction automatically.

Typical workflow:

  1. Use AddDesc() to register all data types needed for an instance
  2. Call AllocateAndConstruct() to create initialized memory
  3. Use GetInstanceData() to access individual data by offset
  4. Call DestructAndDeallocate() when the instance is no longer needed

Member Function Documentation

◆ AddDesc()

xiiUInt32 xiiInstanceDataAllocator::AddDesc ( const xiiInstanceDataDesc & desc)
nodiscard

Adds the given desc to internal list of data that needs to be allocated and returns the byte offset.

Copyright (c) Theophilus Eriata. All Rights Reserved.


The documentation for this class was generated from the following files:
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Memory/InstanceDataAllocator.h
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Memory/Implementation/InstanceDataAllocator.cpp