#include <ObjectPool.hxx>

Public Member Functions | |
| ObjectPool (int nblk) | |
| virtual | ~ObjectPool () |
| X * | getNew () |
| void | destroy (X *obj) |
Private Member Functions | |
| int | getNextFree () |
| void | checkDelete (int chunkId) |
Private Attributes | |
| std::vector< X * > | _chunkList |
| std::vector< bool > | _freeList |
| int | _nextFree |
| int | _maxAvail |
| int | _chunkSize |
Definition at line 27 of file ObjectPool.hxx.
| ObjectPool< X >.ObjectPool | ( | int | nblk | ) |
Definition at line 62 of file ObjectPool.hxx.
{
_chunkSize = nblk;
_nextFree = 0;
_maxAvail = 0;
_chunkList.clear();
_freeList.clear();
}
| virtual ObjectPool< X >.~ObjectPool | ( | ) | [virtual] |
Definition at line 71 of file ObjectPool.hxx.
{
for (int i = 0; i < _chunkList.size(); i++)
delete[] _chunkList[i];
}
| void ObjectPool< X >.checkDelete | ( | int | chunkId | ) | [private] |
Definition at line 48 of file ObjectPool.hxx.
{
int i0 = _chunkSize * chunkId;
int i1 = _chunkSize * (chunkId + 1);
for (int i = i0; i < i1; i++)
if (_freeList[i] == false)
return;
std::cerr << "a chunk to delete" << std::endl;
// compactage des vecteurs un peu lourd, pas necessaire
//X* chunk = _chunkList[chunkId];
//delete [] chunk;
}
| void ObjectPool< X >.destroy | ( | X * | obj | ) |
Definition at line 101 of file ObjectPool.hxx.
Referenced by SMDS_Mesh.AddEdgeWithID(), SMDS_Mesh.AddFaceWithID(), SMDS_Mesh.AddVolumeFromVtkIdsWithID(), SMDS_Mesh.AddVolumeWithID(), SMDS_Mesh.Clear(), SMDS_Mesh.createQuadrangle(), SMDS_Mesh.createTriangle(), SMDS_Mesh.FindEdgeOrCreate(), SMDS_Mesh.RemoveElement(), and SMDS_Mesh.RemoveFreeElement().
{
long adrobj = (long) (obj);
for (int i = 0; i < _chunkList.size(); i++)
{
X* chunk = _chunkList[i];
long adrmin = (long) (chunk);
if (adrobj < adrmin)
continue;
long adrmax = (long) (chunk + _chunkSize);
if (adrobj >= adrmax)
continue;
int rank = (adrobj - adrmin) / sizeof(X);
int toFree = i * _chunkSize + rank;
_freeList[toFree] = true;
if (toFree < _nextFree)
_nextFree = toFree;
//obj->clean();
//checkDelete(i); compactage non fait
break;
}
}
| X* ObjectPool< X >.getNew | ( | ) |
Definition at line 77 of file ObjectPool.hxx.
Referenced by SMDS_Mesh.AddEdgeWithID(), SMDS_Mesh.AddFaceWithID(), SMDS_Mesh.AddNodeWithID(), SMDS_Mesh.AddVolumeFromVtkIdsWithID(), SMDS_Mesh.AddVolumeWithID(), SMDS_Mesh.createQuadrangle(), SMDS_Mesh.createTriangle(), and SMDS_Mesh.FindEdgeOrCreate().
{
X *obj = 0;
_nextFree = getNextFree();
if (_nextFree == _maxAvail)
{
X* newChunk = new X[_chunkSize];
_chunkList.push_back(newChunk);
_freeList.insert(_freeList.end(), _chunkSize, true);
_maxAvail += _chunkSize;
_freeList[_nextFree] = false;
obj = newChunk; // &newChunk[0];
}
else
{
int chunkId = _nextFree / _chunkSize;
int rank = _nextFree - chunkId * _chunkSize;
_freeList[_nextFree] = false;
obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank];
}
//obj->init();
return obj;
}
| int ObjectPool< X >.getNextFree | ( | ) | [private] |
Definition at line 37 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.getNew().
std::vector<X*> ObjectPool< X >._chunkList [private] |
Definition at line 31 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.destroy(), ObjectPool< SMDS_VtkFace >.getNew(), ObjectPool< SMDS_VtkFace >.ObjectPool(), and ObjectPool< SMDS_VtkFace >.~ObjectPool().
int ObjectPool< X >._chunkSize [private] |
Definition at line 35 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.checkDelete(), ObjectPool< SMDS_VtkFace >.destroy(), ObjectPool< SMDS_VtkFace >.getNew(), and ObjectPool< SMDS_VtkFace >.ObjectPool().
std::vector<bool> ObjectPool< X >._freeList [private] |
Definition at line 32 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.checkDelete(), ObjectPool< SMDS_VtkFace >.destroy(), ObjectPool< SMDS_VtkFace >.getNew(), ObjectPool< SMDS_VtkFace >.getNextFree(), and ObjectPool< SMDS_VtkFace >.ObjectPool().
int ObjectPool< X >._maxAvail [private] |
Definition at line 34 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.getNew(), ObjectPool< SMDS_VtkFace >.getNextFree(), and ObjectPool< SMDS_VtkFace >.ObjectPool().
int ObjectPool< X >._nextFree [private] |
Definition at line 33 of file ObjectPool.hxx.
Referenced by ObjectPool< SMDS_VtkFace >.destroy(), ObjectPool< SMDS_VtkFace >.getNew(), ObjectPool< SMDS_VtkFace >.getNextFree(), and ObjectPool< SMDS_VtkFace >.ObjectPool().