Fast RTPS  Version 2.7.1
Fast RTPS
foonathan_memory_helpers.hpp
1 // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
20 #ifndef FASTRTPS_UTILS_COLLECTIONS_FOONATHAN_MEMORY_HELPERS_HPP_
21 #define FASTRTPS_UTILS_COLLECTIONS_FOONATHAN_MEMORY_HELPERS_HPP_
22 
23 #include <foonathan/memory/memory_pool.hpp>
24 #include <foonathan/memory/detail/debug_helpers.hpp>
25 
26 #include "ResourceLimitedContainerConfig.hpp"
27 #include "fastrtps/config.h"
28 
29 namespace eprosima {
30 namespace fastrtps {
31 
43 template <typename MemoryPool>
45  std::size_t node_size,
46  const ResourceLimitedContainerConfig& limits)
47 {
48  FASTDDS_DEPRECATED_UNTIL(3, "eprosima::fastrtps::memory_pool_block_size", "You should not use this method")
49  namespace fm = foonathan::memory;
50 
51  size_t num_elems = limits.increment > 0 ? limits.initial : limits.maximum;
52  if (num_elems < 1u)
53  {
54  num_elems = 1u;
55  }
56 
57  return num_elems
58  * ((node_size > MemoryPool::min_node_size ? node_size : MemoryPool::min_node_size) // Room for elements
59 #if FOONATHAN_MEMORY_DEBUG_DOUBLE_DEALLOC_CHECK
60  * (fm::detail::debug_fence_size ? 3 : 1)) // Room for debug info
61 #else
62  + (fm::detail::debug_fence_size ? 2 * fm::detail::max_alignment : 0)) // Room for debug info
63 #endif // if FOONATHAN_MEMORY_DEBUG_DOUBLE_DEALLOC_CHECK
64 #ifdef FOONATHAN_MEMORY_MEMORY_POOL_HAS_MIN_BLOCK_SIZE
65  + fm::detail::memory_block_stack::implementation_offset(); // Room for padding
66 #else
67  + fm::detail::memory_block_stack::implementation_offset; // Room for padding
68 #endif // FOONATHAN_MEMORY_MEMORY_POOL_HAS_MIN_BLOCK_SIZE
69 }
70 
71 } // namespace fastrtps
72 } // namespace eprosima
73 
74 #endif /* FASTRTPS_UTILS_COLLECTIONS_FOONATHAN_MEMORY_HELPERS_HPP_ */
std::size_t memory_pool_block_size(std::size_t node_size, const ResourceLimitedContainerConfig &limits)
A helper to calculate the block size of a memory pool given the size of the node and a resource limit...
Definition: foonathan_memory_helpers.hpp:44
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23
Specifies the configuration of a resource limited collection.
Definition: ResourceLimitedContainerConfig.hpp:36
size_t increment
Number of items to add when capacity limit is reached.
Definition: ResourceLimitedContainerConfig.hpp:53
size_t maximum
Maximum number of elements allowed in the collection.
Definition: ResourceLimitedContainerConfig.hpp:51
size_t initial
Number of elements to be preallocated in the collection.
Definition: ResourceLimitedContainerConfig.hpp:49