Version: 8.3.0
Main Page
Related Pages
Packages
Data Structures
Files
File List
Globals
SALOME Mesh Module Developer
Use the SpherePadder SMESH Plugin
Todo List
Packages
Data Structures
Files
File List
idl
src
Controls
Driver
DriverCGNS
DriverDAT
DriverGMF
DriverMED
DriverSTL
DriverUNV
MEDWrapper
MEFISTO2
OBJECT
PluginUtils
SMDS
chrono.cxx
chrono.hxx
ObjectPool.hxx
SMDS_BallElement.cxx
SMDS_BallElement.hxx
SMDS_Downward.cxx
SMDS_Downward.hxx
SMDS_EdgePosition.cxx
SMDS_EdgePosition.hxx
SMDS_ElemIterator.hxx
SMDS_FaceOfEdges.cxx
SMDS_FaceOfEdges.hxx
SMDS_FaceOfNodes.cxx
SMDS_FaceOfNodes.hxx
SMDS_FacePosition.cxx
SMDS_FacePosition.hxx
SMDS_Iterator.hxx
SMDS_IteratorOfElements.cxx
SMDS_IteratorOfElements.hxx
SMDS_IteratorOnIterators.hxx
SMDS_LinearEdge.cxx
SMDS_LinearEdge.hxx
SMDS_MemoryLimit.cxx
SMDS_Mesh.cxx
SMDS_Mesh.hxx
SMDS_Mesh0DElement.cxx
SMDS_Mesh0DElement.hxx
SMDS_MeshCell.cxx
SMDS_MeshCell.hxx
SMDS_MeshEdge.cxx
SMDS_MeshEdge.hxx
SMDS_MeshElement.cxx
SMDS_MeshElement.hxx
SMDS_MeshElementIDFactory.cxx
SMDS_MeshElementIDFactory.hxx
SMDS_MeshFace.cxx
SMDS_MeshFace.hxx
SMDS_MeshGroup.cxx
SMDS_MeshGroup.hxx
SMDS_MeshIDFactory.cxx
SMDS_MeshIDFactory.hxx
SMDS_MeshInfo.hxx
SMDS_MeshNode.cxx
SMDS_MeshNode.hxx
SMDS_MeshNodeIDFactory.cxx
SMDS_MeshNodeIDFactory.hxx
SMDS_MeshObject.cxx
SMDS_MeshObject.hxx
SMDS_MeshVolume.cxx
SMDS_MeshVolume.hxx
SMDS_PolygonalFaceOfNodes.cxx
SMDS_PolygonalFaceOfNodes.hxx
SMDS_PolyhedralVolumeOfNodes.cxx
SMDS_PolyhedralVolumeOfNodes.hxx
SMDS_Position.cxx
SMDS_Position.hxx
SMDS_QuadraticEdge.cxx
SMDS_QuadraticEdge.hxx
SMDS_QuadraticFaceOfNodes.cxx
SMDS_QuadraticFaceOfNodes.hxx
SMDS_QuadraticVolumeOfNodes.cxx
SMDS_QuadraticVolumeOfNodes.hxx
SMDS_SetIterator.hxx
SMDS_SpacePosition.cxx
SMDS_SpacePosition.hxx
SMDS_StdIterator.hxx
SMDS_TypeOfPosition.hxx
SMDS_UnstructuredGrid.cxx
SMDS_UnstructuredGrid.hxx
SMDS_VertexPosition.cxx
SMDS_VertexPosition.hxx
SMDS_VolumeOfFaces.cxx
SMDS_VolumeOfFaces.hxx
SMDS_VolumeOfNodes.cxx
SMDS_VolumeOfNodes.hxx
SMDS_VolumeTool.cxx
SMDS_VolumeTool.hxx
SMDS_VtkCellIterator.cxx
SMDS_VtkCellIterator.hxx
SMDS_VtkEdge.cxx
SMDS_VtkEdge.hxx
SMDS_VtkFace.cxx
SMDS_VtkFace.hxx
SMDS_VtkVolume.cxx
SMDS_VtkVolume.hxx
SMDSAbs_ElementType.hxx
SMESH_SMDS.hxx
SMESH
SMESH_I
SMESH_SWIG_WITHIHM
SMESHClient
SMESHDS
SMESHFiltersSelection
SMESHGUI
SMESHUtils
StdMeshers
StdMeshers_I
StdMeshersGUI
Tools
Globals
ObjectPool.hxx
Go to the documentation of this file.
1
// Copyright (C) 2010-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2
//
3
// This library is free software; you can redistribute it and/or
4
// modify it under the terms of the GNU Lesser General Public
5
// License as published by the Free Software Foundation; either
6
// version 2.1 of the License, or (at your option) any later version.
7
//
8
// This library is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
// Lesser General Public License for more details.
12
//
13
// You should have received a copy of the GNU Lesser General Public
14
// License along with this library; if not, write to the Free Software
15
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
//
17
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
//
19
20
#ifndef _OBJECTPOOL_HXX_
21
#define _OBJECTPOOL_HXX_
22
23
#include <vector>
24
//#include <stack>
25
#include <iostream>
26
27
namespace
28
{
29
// assure deallocation of memory of a vector
30
template
<
class
Y>
void
clearVector(std::vector<Y>& v )
31
{
32
std::vector<Y> emptyVec; v.swap( emptyVec );
33
}
34
}
35
36
template
<
class
X>
class
ObjectPool
37
{
38
39
private
:
40
std::vector<X*>
_chunkList
;
41
std::vector<bool>
_freeList
;
42
int
_nextFree
;
43
int
_maxAvail
;
44
int
_chunkSize
;
45
int
_maxOccupied
;
46
int
_nbHoles
;
47
int
_lastDelChunk
;
48
49
int
getNextFree
()
50
{
51
// Don't iterate on the _freeList if all the "holes"
52
// are filled. Go straight to the last occupied ID + 1
53
if
(
_nbHoles
== 0 )
54
return
std::min(
_maxOccupied
+ 1,
_maxAvail
);
55
56
for
(
int
i =
_nextFree
; i <
_maxAvail
; i++)
57
if
(
_freeList
[i] ==
true
)
58
{
59
return
i;
60
break
;
61
}
62
return
_maxAvail
;
63
}
64
65
void
checkDelete
(
int
chunkId)
66
{
67
int
i0 =
_chunkSize
* chunkId;
68
int
i1 =
_chunkSize
* (chunkId + 1);
69
for
(
int
i = i0; i < i1; i++)
70
if
(
_freeList
[i] ==
false
)
71
return
;
72
std::cerr <<
"a chunk to delete"
<< std::endl;
73
// compactage des vecteurs un peu lourd, pas necessaire
74
//X* chunk = _chunkList[chunkId];
75
//delete [] chunk;
76
}
77
78
public
:
79
ObjectPool
(
int
nblk)
80
{
81
_chunkSize
= nblk;
82
_nextFree
= 0;
83
_maxAvail
= 0;
84
_maxOccupied
= 0;
85
_nbHoles
= 0;
86
_chunkList
.clear();
87
_freeList
.clear();
88
_lastDelChunk
= 0;
89
}
90
91
virtual
~ObjectPool
()
92
{
93
for
(
size_t
i = 0; i <
_chunkList
.size(); i++)
94
delete
[]
_chunkList
[i];
95
}
96
97
X*
getNew
()
98
{
99
X *obj = 0;
100
_nextFree
=
getNextFree
();
101
if
(
_nextFree
==
_maxAvail
)
102
{
103
X* newChunk =
new
X[
_chunkSize
];
104
_chunkList
.push_back(newChunk);
105
_freeList
.insert(
_freeList
.end(),
_chunkSize
,
true
);
106
_maxAvail
+=
_chunkSize
;
107
_freeList
[
_nextFree
] =
false
;
108
obj = newChunk;
// &newChunk[0];
109
}
110
else
111
{
112
int
chunkId =
_nextFree
/
_chunkSize
;
113
int
rank =
_nextFree
- chunkId *
_chunkSize
;
114
_freeList
[
_nextFree
] =
false
;
115
obj =
_chunkList
[chunkId] + rank;
// &_chunkList[chunkId][rank];
116
}
117
if
(
_nextFree
<
_maxOccupied
)
118
{
119
_nbHoles
-=1;
120
}
121
else
122
{
123
_maxOccupied
=
_nextFree
;
124
}
125
//obj->init();
126
return
obj;
127
}
128
129
void
destroy
(X* obj)
130
{
131
size_t
i = 0;
132
if
( obj >=
_chunkList
[
_lastDelChunk
] &&
133
obj <
_chunkList
[
_lastDelChunk
] +
_chunkSize
)
134
i =
_lastDelChunk
;
135
else
136
for
( ; i <
_chunkList
.size(); i++ )
137
{
138
if
( obj >=
_chunkList
[ i ] &&
139
obj <
_chunkList
[ i ] +
_chunkSize
)
140
break
;
141
}
142
X* chunk =
_chunkList
[i];
143
long
adrobj = (long) (obj);
144
long
adrmin = (long) (chunk);
145
int
rank = (adrobj - adrmin) /
sizeof
(X);
146
int
toFree = i *
_chunkSize
+ rank;
147
_freeList
[toFree] =
true
;
148
if
(toFree <
_nextFree
)
149
_nextFree
= toFree;
150
if
(toFree <
_maxOccupied
)
151
_nbHoles
+= 1;
152
_lastDelChunk
= i;
153
//obj->clean();
154
//checkDelete(i); compactage non fait
155
}
156
157
void
clear
()
158
{
159
_nextFree
= 0;
160
_maxAvail
= 0;
161
_maxOccupied
= 0;
162
_nbHoles
= 0;
163
_lastDelChunk
= 0;
164
for
(
size_t
i = 0; i <
_chunkList
.size(); i++)
165
delete
[]
_chunkList
[i];
166
clearVector(
_chunkList
);
167
clearVector(
_freeList
);
168
}
169
170
// void destroy(int toFree)
171
// {
172
// // no control 0<= toFree < _freeList.size()
173
// _freeList[toFree] = true;
174
// if (toFree < _nextFree)
175
// _nextFree = toFree;
176
// }
177
178
};
179
180
#endif
src
SMDS
ObjectPool.hxx
Copyright © 2007-2017 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS