Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_MemPool.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef SACADO_FAD_MEMPOOL_HPP
33 #define SACADO_FAD_MEMPOOL_HPP
34 
35 namespace Sacado {
36 
37  namespace Fad {
38 
40  class MemPool {
41 
42  public:
43 
49  MemPool(unsigned int elem_size, unsigned int n_elem,
50  unsigned int pre_alloc = 0);
51 
53  ~MemPool();
54 
56  void* alloc();
57 
59  void free(void *b);
60 
62  unsigned int numChunks() const { return num_chunks; }
63 
64  private:
65 
67  MemPool(const MemPool&);
68 
70  MemPool& operator=(const MemPool&);
71 
73  inline void grow();
74 
75  protected:
76 
78  struct Link {
80  };
81 
83  struct Chunk {
85  char *mem;
86  //~Chunk() { delete [] mem; }
87  };
88 
90  const unsigned int esize;
91 
93  const unsigned int n;
94 
96  const unsigned int csize;
97 
100 
103 
105  unsigned int num_chunks;
106  };
107 
108  } // namespace Fad
109 
110 } // namespace Sacado
111 
112 // Include implementation
113 #include "Sacado_Fad_MemPoolImp.hpp"
114 
115 #endif // SACADO_FAD_MEMPOOL_HPP
const unsigned int csize
Size of memory chunks.
unsigned int num_chunks
Number of allocated chunks.
void free(void *b)
Free an element.
void grow()
Allocate a new chunk.
unsigned int numChunks() const
Return number of allocated chunks.
Chunk * chunks
Pointer to memory chunks.
MemPool(unsigned int elem_size, unsigned int n_elem, unsigned int pre_alloc=0)
Constructor. elem_size is the size of elements, n_elem is the number of elements per chunk...
Represents a memory chunk.
Link * head
Pointer to first free link.
const unsigned int n
Number of elements per chunk.
void * alloc()
Allocate a new element.
MemPool & operator=(const MemPool &)
Private to prohibit copying.
const unsigned int esize
Size of elements in a chunk.