MemoryChannel.AllocMem()

The AllocMem function is a versatile memory allocation utility designed to allocate memory with specific properties based on a variable number of parameters. It uses a structure called MemoryAllocationRequest to define the characteristics of the memory to be allocated, such as size, memory type, data type, dimensions, and additional flags for specialized use cases (e.g., GPU memory, Unicode naming, or parameter packing).

The function prototype is: void* AllocMem(uint64_t tSize, ...), where tSize specifies the total size of the memory to be allocated, and the variable arguments provide detailed configuration through the MemoryAllocationRequest structure or other parameters.

MemoryAllocationRequest Structure

Field Type Description
ma_size uint64_t Size of the memory block to allocate (in bytes).
ma_ram_type uint8_t Memory type (0-6): Heap, Stack, IPC, GPU, Cloud, Registry, Page.
ma_data_type uint8_t Data type (0-7): byte, short, char, int, long, float, double.
ma_dimension_type uint8_t Dimension type (0-7): 1D, 2D, 3D, 4D, 6D, 8D, CustomD.
ma_flags uint8_t Flags for GPU types, Unicode name toggle, and packing enable/disable (via DATA_PACK_PARAMETERS).
padding uint8_t[4] Padding to ensure 64-bit alignment of the next field.
ma_name void* Pointer to a name (can contain a URL).

Memory Type Definitions

Macro Value Description
HEAP_MEMORY 0 Standard heap memory.
STACK_MEMORY 1 Stack-based memory.
IPC_MEMORY 2 Inter-process communication memory.
GPU_MEMORY 3 GPU-accessible memory.
CLOUD_MEMORY 4 Cloud-based memory.
REGISTRY_MEMORY 5 Registry-based memory.
PAGE_MEMORY 6 Paged memory (mapped).
RESERVED_MEMORY 7 Reserved for future use.

Data Type Definitions

Macro Value Description
DATA_PRIMITIVE 0 Single primitive value: byte.
DATA_ARRAY 1 1D array: short.
DATA_2D_ARRAY 2 2D array: char.
DATA_3D_ARRAY 3 3D array: int.
DATA_OBJECT 6 Complex object: long, float, double.

Flag Definitions

Macro Value (Hex) Description
MEMORY_STORE 0x00000008 Memory is stored persistently.
MEMORY_RESIDENT 0x00000010 Memory saved on program exit.
MEMORY_ALLOCATED 0x00000020 Memory is allocated (mapped for PAGE_MEMORY).
MEMORY_LOG_ACCESS 0x00000040 Log memory access events.
MEMORY_NAME_UNICODE 0x00000080 Name is in Unicode format.
MEMORY_GPU_GLOBAL 0x00000100 GPU global memory (CPU-GPU accessible).
MEMORY_GPU_SHARED 0x00000200 GPU on-chip shared memory.
MEMORY_GPU_TEXTURE 0x00000400 GPU texture memory (array of rectangles).
MEMORY_GPU_LOCAL 0x00000800 GPU local thread memory.
DATA_SIGNED 0x40 Data is signed (not applicable to objects).
DATA_PACK_PARAMETERS 0x80 Enable/disable packing of parameters (SolidPod).

Decoding Example

The DECODE_CHANNEL_DATA macro extracts information from an encoded input value using bitwise operations. Here's an example of its usage:

#define DECODE_CHANNEL_DATA(input, memoryType, primitiveType, dimensionBits, packedParameters, isSigned) do { \
    memoryType = MEMORY_TYPE(input); \
    primitiveType = PRIMITIVE_TYPE(input); \
    dimensionBits = DIMENSION_TYPE(input); \
    packedParameters = IS_PACKED_PARAMETERS(input); \
    isSigned = IS_SIGNED(input) ? 1 : 0; \
} while (0)
    

This macro decodes the memory type, primitive type, dimension bits, packed parameters, and signed status from a single input value, making it easier to interpret the configuration of allocated memory. The DATA_PACK_PARAMETERS flag (0x80) serves as an enable/disable toggle for parameter packing, and the struct is 64-bit aligned with explicit padding.