iceoryx_doc  1.0.1
memory_manager.hpp
1 // Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_POSH_MEPOO_MEMORY_MANAGER_HPP
18 #define IOX_POSH_MEPOO_MEMORY_MANAGER_HPP
19 
20 #include "iceoryx_posh/iceoryx_posh_types.hpp"
21 #include "iceoryx_posh/internal/mepoo/mem_pool.hpp"
22 #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
23 #include "iceoryx_posh/mepoo/chunk_settings.hpp"
24 #include "iceoryx_utils/cxx/helplets.hpp"
25 #include "iceoryx_utils/cxx/vector.hpp"
26 
27 #include <cstdint>
28 #include <limits>
29 
30 // this header must always be the last one, otherwise windows macros
31 // are kicking in and nothing compiles
32 #include "iceoryx_utils/platform/platform_correction.hpp"
33 
34 namespace iox
35 {
36 namespace log
37 {
38 class LogStream;
39 }
40 namespace mepoo
41 {
42 struct MePooConfig;
43 
45 {
46  using MaxChunkPayloadSize_t = cxx::range<uint32_t, 1, std::numeric_limits<uint32_t>::max() - sizeof(ChunkHeader)>;
47 
48  public:
49  MemoryManager() noexcept = default;
50  MemoryManager(const MemoryManager&) = delete;
51  MemoryManager(MemoryManager&&) = delete;
52  MemoryManager& operator=(const MemoryManager&) = delete;
53  MemoryManager& operator=(MemoryManager&&) = delete;
54  ~MemoryManager() noexcept = default;
55 
56  void configureMemoryManager(const MePooConfig& mePooConfig,
57  posix::Allocator& managementAllocator,
58  posix::Allocator& chunkMemoryAllocator) noexcept;
59 
60  SharedChunk getChunk(const ChunkSettings& chunkSettings) noexcept;
61 
62  uint32_t getNumberOfMemPools() const noexcept;
63 
64  MemPoolInfo getMemPoolInfo(const uint32_t index) const noexcept;
65 
66  static uint64_t requiredChunkMemorySize(const MePooConfig& mePooConfig) noexcept;
67  static uint64_t requiredManagementMemorySize(const MePooConfig& mePooConfig) noexcept;
68  static uint64_t requiredFullMemorySize(const MePooConfig& mePooConfig) noexcept;
69 
70  private:
71  static uint32_t sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) noexcept;
72 
73  void printMemPoolVector(log::LogStream& log) const noexcept;
74  void addMemPool(posix::Allocator& managementAllocator,
75  posix::Allocator& chunkMemoryAllocator,
76  const cxx::greater_or_equal<uint32_t, MemPool::CHUNK_MEMORY_ALIGNMENT> chunkPayloadSize,
77  const cxx::greater_or_equal<uint32_t, 1> numberOfChunks) noexcept;
78  void generateChunkManagementPool(posix::Allocator& managementAllocator) noexcept;
79 
80  private:
81  bool m_denyAddMemPool{false};
82  uint32_t m_totalNumberOfChunks{0};
83 
84  cxx::vector<MemPool, MAX_NUMBER_OF_MEMPOOLS> m_memPoolVector;
85  cxx::vector<MemPool, 1> m_chunkManagementPool;
86 };
87 
88 } // namespace mepoo
89 } // namespace iox
90 
91 #endif // IOX_POSH_MEPOO_MEMORY_MANAGER_HPP
Definition: chunk_settings.hpp:30
Definition: memory_manager.hpp:45
WARNING: SharedChunk is not thread safe! Don't share SharedChunk objects between threads!...
Definition: shared_chunk.hpp:35
Definition: service_description.hpp:29
Definition: chunk_header.hpp:42
Definition: mepoo_config.hpp:33
Definition: mem_pool.hpp:35