alignedAlloc

fnvoid * alignedAlloc(size_t nBlocks, size_t nBlockBytes, size_t alignment)

This function is similar to [glib.global.gmalloc], allocating (n_blocks * n_block_bytes) bytes, but care is taken to align the allocated memory to with the given alignment value. Additionally, it will detect possible overflow during multiplication.

If the allocation fails (because the system is out of memory), the program is terminated.

Aligned memory allocations returned by this function can only be freed using [glib.global.alignedFreeSized] or [glib.global.alignedFree].

Parameters

nBlocksthe number of blocks to allocate
nBlockBytesthe size of each block in bytes
alignmentthe alignment to be enforced, which must be a positive power of 2 and a multiple of sizeof(void*)

Returns

the allocated memory