Sacado Package Browser (Single Doxygen Collection)
Version of the Day
src
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
{
79
Link
*
next
;
80
};
81
83
struct
Chunk
{
84
Chunk
*
next
;
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
99
Chunk
*
chunks
;
100
102
Link
*
head
;
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
Sacado::Fad::MemPool::Chunk::next
Chunk * next
Definition:
Sacado_Fad_MemPool.hpp:84
Sacado::Fad::MemPool::Chunk::mem
char * mem
Definition:
Sacado_Fad_MemPool.hpp:85
Sacado::Fad::MemPool::chunks
Chunk * chunks
Pointer to memory chunks.
Definition:
Sacado_Fad_MemPool.hpp:99
Sacado::Fad::MemPool
Memory pool.
Definition:
Sacado_Fad_MemPool.hpp:40
Sacado::Fad::MemPool::n
const unsigned int n
Number of elements per chunk.
Definition:
Sacado_Fad_MemPool.hpp:93
Sacado::Fad::MemPool::Chunk
Represents a memory chunk.
Definition:
Sacado_Fad_MemPool.hpp:83
Sacado::Fad::MemPool::numChunks
unsigned int numChunks() const
Return number of allocated chunks.
Definition:
Sacado_Fad_MemPool.hpp:62
Sacado::Fad::MemPool::~MemPool
~MemPool()
Destructor.
Definition:
Sacado_Fad_MemPoolImp.hpp:51
Sacado::Fad::MemPool::alloc
void * alloc()
Allocate a new element.
Definition:
Sacado_Fad_MemPoolImp.hpp:62
Sacado::Fad::MemPool::head
Link * head
Pointer to first free link.
Definition:
Sacado_Fad_MemPool.hpp:102
Sacado::Fad::MemPool::MemPool
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....
Definition:
Sacado_Fad_MemPoolImp.hpp:35
Sacado::Fad::MemPool::Link
Represents a memory element.
Definition:
Sacado_Fad_MemPool.hpp:78
Sacado::Fad::MemPool::grow
void grow()
Allocate a new chunk.
Definition:
Sacado_Fad_MemPoolImp.hpp:83
Sacado::Fad::MemPool::operator=
MemPool & operator=(const MemPool &)
Private to prohibit copying.
Sacado::Fad::MemPool::Link::next
Link * next
Definition:
Sacado_Fad_MemPool.hpp:79
Sacado
Definition:
Sacado_mpl_apply.hpp:39
Sacado::Fad::MemPool::csize
const unsigned int csize
Size of memory chunks.
Definition:
Sacado_Fad_MemPool.hpp:96
Sacado::Fad::MemPool::free
void free(void *b)
Free an element.
Definition:
Sacado_Fad_MemPoolImp.hpp:73
Sacado_Fad_MemPoolImp.hpp
Sacado::Fad::MemPool::num_chunks
unsigned int num_chunks
Number of allocated chunks.
Definition:
Sacado_Fad_MemPool.hpp:105
Sacado::Fad::MemPool::esize
const unsigned int esize
Size of elements in a chunk.
Definition:
Sacado_Fad_MemPool.hpp:90
Generated by
1.8.16