Function rcutils_string_map_reserve

Function Documentation

rcutils_ret_t rcutils_string_map_reserve(rcutils_string_map_t *string_map, size_t capacity)

Reserve a given amount of capacity in the map.

Increases the capacity of the map to at least the given size.

If the current capacity is less than requested capacity then the capacity is increased using the allocator given during initialization of the map in rcutils_string_map_init(). If the requested capacity is less than the current capacity, the capacity may be reduced, but no existing key value pairs will be truncated to do so. In effect, the capacity will be shrunk to fit the number of items in map or the requested capacity, which ever is larger.

If recovering all resources is desired first call rcutils_string_map_clear() and then this function with a capacity of 0.

Parameters:
  • string_map[inout] rcutils_string_map_t to have space reserved in

  • capacity[in] requested size to reserve in the map

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_STRING_MAP_INVALID if the string map is invalid, or

Returns:

RCUTILS_RET_ERROR if an unknown error occurs.