Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mempool.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_BIDIR_MEMPOOL_H_)
21 #define __MITSUBA_BIDIR_MEMPOOL_H_
22 
23 #include <mitsuba/bidir/vertex.h>
24 #include <mitsuba/bidir/edge.h>
25 #include <mitsuba/core/mempool.h>
26 
28 
29 class MemoryPool {
30 public:
31  /// Create a new memory pool with aninitial set of 128 entries
32  MemoryPool(size_t nEntries = 128)
33  : m_vertexPool(nEntries), m_edgePool(nEntries) { }
34 
35  /// Destruct the memory pool and release all entries
37 
38  /// Acquire an edge
39  inline PathEdge *allocEdge() {
40  PathEdge *edge = m_edgePool.alloc();
41  #if defined(MTS_BD_DEBUG_HEAVY)
42  memset(edge, 0xFF, sizeof(PathEdge));
43  #endif
44  return edge;
45  }
46 
47  /// Acquire an vertex
48  inline PathVertex *allocVertex() {
49  PathVertex *vertex = m_vertexPool.alloc();
50  #if defined(MTS_BD_DEBUG_HEAVY)
51  memset(vertex, 0xFF, sizeof(PathVertex));
52  #endif
53  return vertex;
54  }
55 
56  /// Release an edge
57  inline void release(PathEdge *edge) {
58  m_edgePool.release(edge);
59  }
60 
61  /// Release an entry
62  inline void release(PathVertex *vertex) {
63  m_vertexPool.release(vertex);
64  }
65 
66  /// Check if every entry has been released
67  bool unused() const {
68  return m_vertexPool.unused() && m_edgePool.unused();
69  }
70 
71  /// Return the currently allocated amount of storage for edges
72  inline size_t edgeSize() {
73  return m_edgePool.size();
74  }
75 
76  /// Return the currently allocated amount of storage for vertices
77  inline size_t vertexSize() {
78  return m_vertexPool.size();
79  }
80 
81  /// Return a human-readable description
82  std::string toString() const {
83  std::ostringstream oss;
84  oss << "MemoryPool[" << endl
85  << " vertexPool = " << m_vertexPool.toString() << "," << endl
86  << " edgePool = " << m_edgePool.toString() << endl
87  << "]";
88  return oss.str();
89  }
90 
91 private:
92  BasicMemoryPool<PathVertex> m_vertexPool;
93  BasicMemoryPool<PathEdge> m_edgePool;
94 };
95 
97 
98 #endif /* __MITSUBA_BIDIR_MEMPOOL_H_ */
void release(PathEdge *edge)
Release an edge.
Definition: mempool.h:57
void release(PathVertex *vertex)
Release an entry.
Definition: mempool.h:62
Bidirectional path vertex data structure.
Definition: vertex.h:48
bool unused() const
Check if every entry has been released.
Definition: mempool.h:67
PathVertex * allocVertex()
Acquire an vertex.
Definition: mempool.h:48
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Basic memory pool for efficient allocation and deallocation of objects of the same type...
Definition: mempool.h:42
PathEdge * allocEdge()
Acquire an edge.
Definition: mempool.h:39
std::string toString() const
Return a human-readable description.
Definition: mempool.h:82
Bidirectional path edge data structure.
Definition: edge.h:46
MemoryPool(size_t nEntries=128)
Create a new memory pool with aninitial set of 128 entries.
Definition: mempool.h:32
~MemoryPool()
Destruct the memory pool and release all entries.
Definition: mempool.h:36
size_t vertexSize()
Return the currently allocated amount of storage for vertices.
Definition: mempool.h:77
size_t edgeSize()
Return the currently allocated amount of storage for edges.
Definition: mempool.h:72
Definition: mempool.h:29
#define MTS_NAMESPACE_END
Definition: platform.h:138