Function rcutils_char_array_resize
Defined in File char_array.h
Function Documentation
-
rcutils_ret_t rcutils_char_array_resize(rcutils_char_array_t *char_array, size_t new_size)
Resize the internal buffer of the char array.
The internal buffer of the char array can be resized dynamically if needed. If the new size is smaller than the current capacity, then the memory is truncated. Be aware, that this will deallocate the memory and therefore invalidates any pointers to this storage. If the new size is larger, new memory is getting allocated and the existing content is copied over. Note that if the array doesn’t own the current buffer the function just allocates a new block of memory and copies the contents of the old buffer instead of resizing the existing buffer.
- Parameters:
char_array – [in] pointer to the instance of rcutils_char_array_t which is being resized
new_size – [in] the new size of the internal buffer
- Returns:
RCUTILS_RET_OK if successful, or
- Returns:
RCUTILS_RET_INVALID_ARGUMENT if new_size is set to zero
- Returns:
RCUTILS_RET_BAD_ALLOC if memory allocation failed, or
- Returns:
RCUTILS_RET_ERROR if an unexpected error occurs.