The default memory allocation routine.
PVOID XMemAllocDefault(
SIZE_T dwSize, ULONGLONG dwAttributes)
dwSize
Type: SIZE_T
[in] Size of the memory block that is being requested.
dwAttributes
Type: ULONGLONG
[in] Attributes of the allocation. Refer to XALLOC_ATTRIBUTES.
Type: PVOID
Returns a pointer to the allocated memory block.
Two default functions are exported by the system: XMemAllocDefault and XMemFreeDefault. These represent the initial values of the allocation hooks. If titles choose not to provide their own allocation hooks, these system default allocators will be used instead. If titles desire to provide allocation hooks for the sake of tracking, but do not wish to implement their own allocator, they can call into the default allocator directly.
XMemAllocDefault takes the same parameters as XMemAlloc. It provides the operating-system implementation of XMemAlloc for titles which do not want to hook the behavior, or that want to fall back to the default behavior for cases it does not handle.
The Xbox Platform funnels nearly all allocations through XMemAlloc which provides developers with the opportunity to monitor or handle the memory requirements of the platform. Titles are welcome to supply their own memory managers for some or all of the requests that come through XMemAlloc. For the remainder, the XMemAllocDefault API is used. XMemAllocDefault services allocation requests through one of three mechanisms: HeapAlloc, VirtualAlloc, or a series of internally managed heaps. The decision of which of these three mechanisms to use depends on the type and alignment requirements of the allocation.

Every allocation of type XALLOC_MEMTYPE_HEAP_CACHEABLE will go to HeapAlloc as long as it specifies an alignment <= 16 bytes and a page size of 4 KB.
Otherwise, every allocation of type XALLOC_MEMTYPE_PHYSICAL_* will go to VirtualAlloc. Allocations requesting 4 KB or 64 KB pages will specify the MEM_LARGE_PAGES on the call to VirtualAlloc and allocations requesting 4 MB pages will specify MEM_4MB_PAGES on the call to VirtualAlloc. These flags are needed to ensure that the allocation cannot be relocated in the physical address space.
Otherwise, every allocation that is > 128 KB or that requires alignment of >= 64 KB will go to VirtualAlloc. Allocations of type XALLOC_MEMTYPE_GRAPHICS_* will specify MEM_GRAPHICS on the call to VirtualAlloc, and allocations will specify a page size appropriate for the size specified in the allocation attributes (graphics allocations will be promoted to a minimum page size of 64 KB).
Otherwise, the allocation will be handled by XMemAllocDefault’s internal heap. There are two heaps for each of the 10 documented allocation types; one handles allocations < 4 KB with alignment <= 4 KB (the “small block” heap) and the other handles all other allocations (the “large block” heap). This adds up to 20 heaps total.
Header: Declared in xmem.h.