rcl
beta1
C API providing common ROS client library functionality.
|
Encapsulation of an allocator. More...
#include <allocator.h>
Public Attributes | |
void *(* | allocate )(size_t size, void *state) |
Allocate memory, given a size and the state pointer. More... | |
void(* | deallocate )(void *pointer, void *state) |
Deallocate previously allocated memory, mimicking std::free(). More... | |
void *(* | reallocate )(void *pointer, size_t size, void *state) |
Reallocate if possible, otherwise it deallocates and allocates. More... | |
void * | state |
Implementation defined state storage. More... | |
Encapsulation of an allocator.
The default allocator uses std::malloc(), std::free(), and std::realloc(). It can be obtained using rcl_get_default_allocator().
The allocator should be trivially copyable. Meaning that the struct should continue to work after being assignment copied into a new struct. Specifically the object pointed to by the state pointer should remain valid until all uses of the allocator have been made. Particular care should be taken when giving an allocator to rcl_init_* where it is stored within another object and used later.
void*(* rcl_allocator_t::allocate) (size_t size, void *state) |
Allocate memory, given a size and the state
pointer.
An error should be indicated by returning NULL
.
void(* rcl_allocator_t::deallocate) (void *pointer, void *state) |
Deallocate previously allocated memory, mimicking std::free().
Also takes the state
pointer.
void*(* rcl_allocator_t::reallocate) (void *pointer, size_t size, void *state) |
Reallocate if possible, otherwise it deallocates and allocates.
Also takes the state
pointer.
If unsupported then do deallocate and then allocate. This should behave as std::realloc() does, as opposed to posix's reallocf, i.e. the memory given by pointer will not be free'd automatically if std::realloc() fails. For reallocf-like behavior use rcl_reallocf(). This function must be able to take an input pointer of NULL
and succeed.
void* rcl_allocator_t::state |
Implementation defined state storage.
This is passed as the final parameter to other allocator functions.