iceoryx_doc  1.0.1
allocator.hpp
1 // Copyright (c) 2019 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_UTILS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_ALLOCATOR_HPP
18 #define IOX_UTILS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_ALLOCATOR_HPP
19 
20 #include <cstdint>
21 namespace iox
22 {
23 namespace posix
24 {
25 class SharedMemoryObject;
26 
27 class Allocator
28 {
29  using byte_t = uint8_t;
30 
31 
32  public:
33  static constexpr uint64_t MEMORY_ALIGNMENT = 8U;
37  Allocator(void* const startAddress, const uint64_t length) noexcept;
38 
39  Allocator(const Allocator&) = delete;
40  Allocator(Allocator&&) noexcept = default;
41  Allocator& operator=(const Allocator&) noexcept = delete;
42  Allocator& operator=(Allocator&&) = default;
43  ~Allocator() = default;
44 
49  void* allocate(const uint64_t size, const uint64_t alignment) noexcept;
50 
51  protected:
52  friend class SharedMemoryObject;
53  void finalizeAllocation() noexcept;
54 
55  private:
56  byte_t* m_startAddress{nullptr};
57  uint64_t m_length{0u};
58  uint64_t m_currentPosition = 0u;
59  bool m_allocationFinalized = false;
60 };
61 } // namespace posix
62 } // namespace iox
63 
64 #endif // IOX_UTILS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_ALLOCATOR_HPP
Definition: allocator.hpp:28
Allocator(void *const startAddress, const uint64_t length) noexcept
A bump allocator for the memory provided in the ctor arguments.
void * allocate(const uint64_t size, const uint64_t alignment) noexcept
allocates on the memory supplied with the ctor
Definition: shared_memory_object.hpp:43
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28