Aligned memory allocator. More...
Functions | |
size_t | rapp_align (size_t size) |
Align (round up) to the next alignment boundary. | |
int | rapp_validate_buffer (uint8_t *ptr, const int dim, const int width, const int height) |
Validate that a pixel buffer is properly allocated for use with RAPP functions. | |
void * | rapp_malloc (size_t size, unsigned hint) |
Allocate an aligned chunk of memory. | |
void | rapp_free (void *ptr) |
Free an aligned chunk of memory. | |
Variables | |
const unsigned int | rapp_alignment |
The required pixel buffer and row length alignment in bytes. |
Aligned memory allocator.
This is an allocator for allocating aligned pixel buffers suitable for use with the RAPP library. The size of the allocated memory is rounded up to the nearest multiple of rapp_alignment. The value of rapp_alignment is undefined before rapp_initialize() has been called. Memory allocated by this allocator must never be released by another allocator like malloc()/free() or vice-versa.
There is a mechanism for passing allocation strategy hints. Currently no hints are available, so the value 0 must always be used.
size_t rapp_align | ( | size_t | size | ) |
Align (round up) to the next alignment boundary.
size | The required size in bytes. |
int rapp_validate_buffer | ( | uint8_t * | ptr, | |
const int | dim, | |||
const int | width, | |||
const int | height | |||
) |
Validate that a pixel buffer is properly allocated for use with RAPP functions.
The purpose is to test that a chunk of memory that has been allocated using an unknown allocation method, is valid for use with RAPP functions. A failed test means that it must instead be copied to a valid buffer (typically allocated using rapp_malloc) with a row dimension that is a multiple of rapp_alignment. This function does not exclude use with RAPP functions explicitly allowing misaligned image buffers, but note that those functions have their own validity requirements. Note also that this function does not check the buffer allocation length, i.e. that buffer has been allocated to the stated size. It is not necessary to test a buffer allocated with rapp_malloc and used with a rapp_alignment row dimension.
ptr | The u8 image buffer to validate. | |
dim | Buffer row dimension in bytes. | |
width | Image width in pixels. | |
height | Image height in pixels. |
void* rapp_malloc | ( | size_t | size, | |
unsigned | hint | |||
) |
Allocate an aligned chunk of memory.
size | The number of bytes to allocate. | |
hint | Allocation hint flags. Pass 0 for no hint. |
void rapp_free | ( | void * | ptr | ) |
Free an aligned chunk of memory.
ptr | An aligned pointer obtained from rapp_malloc(). If the value is NULL no action is performed. |
const unsigned int rapp_alignment |
The required pixel buffer and row length alignment in bytes.
The value is at least four bytes.