GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
volk_malloc.h File Reference
#include <volk/volk_common.h>
#include <stdlib.h>
Include dependency graph for volk_malloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

__VOLK_DECL_BEGIN VOLK_API voidvolk_malloc (size_t size, size_t alignment)
 Allocate size bytes of data aligned to alignment. More...
 
VOLK_API void volk_free (void *aptr)
 Free's memory allocated by volk_malloc. More...
 

Function Documentation

VOLK_API void volk_free ( void aptr)

Free's memory allocated by volk_malloc.

Parameters
aptrThe aligned pointer allocaed by volk_malloc.
__VOLK_DECL_BEGIN VOLK_API void* volk_malloc ( size_t  size,
size_t  alignment 
)

Allocate size bytes of data aligned to alignment.

Because we don't have a standard method to allocate buffers in memory that are guaranteed to be on an alignment, VOLK handles this itself. The volk_malloc function behaves like malloc in that it returns a pointer to the allocated memory. However, it also takes in an alignment specfication, which is usually something like 16 or 32 to ensure that the aligned memory is located on a particular byte boundary for use with SIMD.

Internally, the volk_malloc first checks if the compiler is C11 compliant and uses the new aligned_alloc method. If not, it checks if the system is POSIX compliant and uses posix_memalign. If that fails, volk_malloc handles the memory allocation and alignment internally.

Because of the ways in which volk_malloc may allocate memory, it is important to always free volk_malloc pointers using volk_free.

Parameters
sizeThe number of bytes to allocate.
alignmentThe byte alignment of the allocated memory.
Returns
pointer to aligned memory.