supereight
memory_pool.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3  * SPDX-FileCopyrightText: 2020-2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
4  * SPDX-FileCopyrightText: 2020-2021 Nils Funk
5  * SPDX-FileCopyrightText: 2020-2021 Sotiris Papatheodorou
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef SE_MEMORY_POOL_HPP
10 #define SE_MEMORY_POOL_HPP
11 
12 #include <Eigen/Dense>
13 #include <boost/pool/pool.hpp>
14 
15 namespace se {
16 
17 
18 
19 template<typename NodeT, typename BlockT>
21  public:
22  typedef typename NodeT::DataType DataType;
23 
24  BoostMemoryPool() : node_buffer_(sizeof(NodeT)), block_buffer_(sizeof(BlockT))
25  {
26  }
27 
33  inline NodeT* allocateNode(const Eigen::Vector3i& node_coord, const unsigned int node_size)
34  {
35  return new (node_buffer_.malloc()) NodeT(node_coord, node_size, DataType());
36  }
37 
47  inline NodeT* allocateNode(NodeT* parent_ptr, const int child_idx, const DataType init_data)
48  {
49  return new (node_buffer_.malloc()) NodeT(parent_ptr, child_idx, init_data);
50  }
51 
61  inline BlockT* allocateBlock(NodeT* parent_ptr, const int child_idx, const DataType init_data)
62  {
63  return new (block_buffer_.malloc()) BlockT(parent_ptr, child_idx, init_data);
64  }
65 
69  inline void deleteNode(NodeT* node_ptr)
70  {
71  node_ptr->~NodeT();
72  node_buffer_.free(node_ptr);
73  }
74 
78  inline void deleteBlock(BlockT* block_ptr)
79  {
80  block_ptr->~BlockT();
81  block_buffer_.free(block_ptr);
82  }
83 
84  boost::pool<> node_buffer_;
85  boost::pool<> block_buffer_;
86 };
87 
88 } // namespace se
89 
90 #endif // SE_MEMORY_POOL_HPP
void deleteNode(NodeT *node_ptr)
Delete a given node.
Definition: memory_pool.hpp:69
boost::pool block_buffer_
The block buffer.
Definition: memory_pool.hpp:85
NodeT::DataType DataType
Definition: memory_pool.hpp:22
Definition: memory_pool.hpp:20
void deleteBlock(BlockT *block_ptr)
Delete a given block.
Definition: memory_pool.hpp:78
NodeT * allocateNode(const Eigen::Vector3i &node_coord, const unsigned int node_size)
Allocate a node using its coordinates and size.
Definition: memory_pool.hpp:33
BoostMemoryPool()
Definition: memory_pool.hpp:24
BlockT * allocateBlock(NodeT *parent_ptr, const int child_idx, const DataType init_data)
Allocate a block using its parent and child index.
Definition: memory_pool.hpp:61
boost::pool node_buffer_
The node buffer.
Definition: memory_pool.hpp:84
NodeT * allocateNode(NodeT *parent_ptr, const int child_idx, const DataType init_data)
Allocate a node using its parent and child index.
Definition: memory_pool.hpp:47
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17