Memory Allocation

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.

Detailed Description

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.

Next section: Error Handling


Function Documentation

size_t rapp_align ( size_t  size  ) 

Align (round up) to the next alignment boundary.

Parameters:
size The required size in bytes.
Returns:
The nearest number greater than or equal to size that is a multiple of rapp_alignment.
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.

Parameters:
ptr The u8 image buffer to validate.
dim Buffer row dimension in bytes.
width Image width in pixels.
height Image height in pixels.
Returns:
1 if buffer has a valid alignment. 0 if buffer's memory alignment or dimensions does not meet RAPP's requirements. -1 if the RAPP library is not initialized.
void* rapp_malloc ( size_t  size,
unsigned  hint 
)

Allocate an aligned chunk of memory.

Parameters:
size The number of bytes to allocate.
hint Allocation hint flags. Pass 0 for no hint.
Returns:
An aligned pointer to allocated memory of size rapp_align(size), or NULL if memory allocation failed.
void rapp_free ( void *  ptr  ) 

Free an aligned chunk of memory.

Parameters:
ptr An aligned pointer obtained from rapp_malloc(). If the value is NULL no action is performed.

Variable Documentation

const unsigned int rapp_alignment

The required pixel buffer and row length alignment in bytes.

The value is at least four bytes.


Generated on 1 Jun 2016 for RAPP by  doxygen 1.6.1