MAKE_XALLOC_ATTRIBUTES

Inline helper function used to compose the dwAttributes parameter to XMEMALLOC_ROUTINE.

Syntax

ULONGLONG MAKE_XALLOC_ATTRIBUTES(
         ULONGLONG dwAllocatorId,
         ULONGLONG dwObjectType,
         ULONGLONG dwMemoryType,
         ULONGLONG dwPageSize,
         ULONGLONG dwAlignment
)  

Parameters

dwAllocatorId
Type: ULONGLONG 

[in] ID of the subsystem performing the allocation. Each allocation is associated with an allocator ID, which identifies the subsystem which is requesting the allocation (or free). There are three potential sources of allocations: Title, Platform and Middleware components. For value ranges, see XALLOC_ALLOCATOR_IDS.

dwObjectType
Type: ULONGLONG 

[in] Allocation type, as defined by the subsystem performing the allocation.

dwMemoryType
Type: ULONGLONG 

[in] The memory type required.

dwPageSize
Type: ULONGLONG 

[in] The page size allocated. The size may not be aligned to any value in particular, and allocators implementing this hook are not expected to round allocation sizes to any value in particular, irrespective of the page size implied by the allocation flags.

dwAlignment
Type: ULONGLONG 

[in] The type of alignment required. For example, 16-byte alignment will specify 16, page alignment will specify 4096, etc. A value of zero means that no specific alignment is requested.

Return value

Type: ULONGLONG 

A value containing the attributes to be used in the memory allocation.

Example

The following example shows how to define allocator IDs for a particle system, then use the ID in a call to MAKE_XALLOC_ATTRIBUTES, and finally call XMemAlloc with those attributes. The example defines AllocatorId as TitleAllocatorID_ParticleSystem = 4 and defines a pool to contain particles which only collide with the ground-plane in the engine. This pool has the ObjectType ID of 2, because 0 is already defined for emitters, and 1 is defined for particles that did collide.

enum TitleAllocatorIDs
{
      AllocID_Textures = eXALLOCAllocatorId_GameMin,
      AllocID_ParticleSystem,
      AllocID_Scripts,
      AllocID_Meshes,
      AllocID_AI,
      AllocID_AudioData,
      AllocID_Networking
};

enum ParticleObjectAllocTypes
{
      ParticleAllocType_EmitterPool = 0,
      ParticleAllocType_CollidableParticlesPool = 1,
      ParticleAllocType_NonCollisionParticlesPool = 2
};

struct EmitterPool;
const SIZE_T EmitterPoolSize = 1024*256; //256KB pool.

EmitterPool* AllocParticleSystemEmitterPool()
{
      XALLOC_ATTRIBUTES attr = MAKE_XALLOC_ATTRIBUTES(
      AllocID_ParticleSystem,
      ParticleAllocType_EmitterPool,
      XALLOC_MEMTYPE_HEAP_CACHEABLE,
      XALLOC_PAGESIZE_4MB,
      XALLOC_ALIGNMENT_64K );
      return (EmitterPool*)XMemAlloc( EmitterPoolSize, attr );
}  

See also

XALLOC_ATTRIBUTES

Requirements

Header: Declared in xmem.h.