Function

GLibaligned_alloc

Declaration

gpointer
g_aligned_alloc (
  gsize n_blocks,
  gsize n_block_bytes,
  gsize alignment
)

Description

This function is similar to g_malloc(), 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.

Aligned memory allocations returned by this function can only be freed using g_aligned_free().

Available since:2.72

Parameters

n_blocks gsize
 

The number of blocks to allocate.

n_block_bytes gsize
 

The size of each block in bytes.

alignment gsize
 

The alignment to be enforced, which must be a positive power of 2 and a multiple of sizeof(void*)

Return value

Returns: gpointer
 

The allocated memory.

 The caller of the function takes ownership of the data, and is responsible for freeing it.
 The return value can be NULL.