Function rcutils_array_list_init
Defined in File array_list.h
Function Documentation
-
rcutils_ret_t rcutils_array_list_init(rcutils_array_list_t *array_list, size_t initial_capacity, size_t data_size, const rcutils_allocator_t *allocator)
Initialize an array list with a given initial capacity.
This function will initialize a given, zero initialized, array_list to a given size.
Attribute
Adherence
Allocates Memory
Yes
Thread-Safe
No
Uses Atomics
No
Lock-Free
Yes
Example:
rcutils_allocator_t allocator = rcutils_get_default_allocator(); rcutils_array_list_t array_list = rcutils_get_zero_initialized_array_list(); rcutils_ret_t ret = rcutils_array_list_init(&array_list, 2, sizeof(int), &allocator); if (ret != RCUTILS_RET_OK) { // ... error handling } int data = 42; int out_data = 0; ret = rcutils_array_list_add(&array_list, &data); data++; ret = rcutils_array_list_get(&array_list, 0, &out_data); assert(42 == out_data); ret = rcutils_array_list_fini(&array_list);
- Parameters:
array_list – [inout] object to be initialized
initial_capacity – [in] the initial capacity to allocate in the list
data_size – [in] the size (in bytes) of the data object being stored in the list
allocator – [in] to be used to allocate and deallocate memory
- Returns:
RCUTILS_RET_OK if successful, or
- Returns:
RCUTILS_RET_INVALID_ARGUMENT for invalid arguments, or
- Returns:
RCUTILS_RET_BAD_ALLOC if memory allocation fails, or
- Returns:
RCUTILS_RET_ERROR if an unknown error occurs.