1 #ifndef _OBJECTPOOL_HXX_
2 #define _OBJECTPOOL_HXX_
8 template<class X> class ObjectPool
12 std::vector<X*> _chunkList;
13 std::vector<bool> _freeList;
20 for (int i = _nextFree; i < _maxAvail; i++)
21 if (_freeList[i] == true)
29 void checkDelete(int chunkId)
31 int i0 = _chunkSize * chunkId;
32 int i1 = _chunkSize * (chunkId + 1);
33 for (int i = i0; i < i1; i++)
34 if (_freeList[i] == false)
36 std::cerr << "a chunk to delete" << std::endl;
37 // compactage des vecteurs un peu lourd, pas necessaire
38 //X* chunk = _chunkList[chunkId];
54 for (int i = 0; i < _chunkList.size(); i++)
55 delete[] _chunkList[i];
61 _nextFree = getNextFree();
62 if (_nextFree == _maxAvail)
64 X* newChunk = new X[_chunkSize];
65 _chunkList.push_back(newChunk);
66 _freeList.insert(_freeList.end(), _chunkSize, true);
67 _maxAvail += _chunkSize;
68 _freeList[_nextFree] = false;
69 obj = newChunk; // &newChunk[0];
73 int chunkId = _nextFree / _chunkSize;
74 int rank = _nextFree - chunkId * _chunkSize;
75 _freeList[_nextFree] = false;
76 obj = _chunkList[chunkId] + rank; // &_chunkList[chunkId][rank];
84 long adrobj = (long) (obj);
85 for (int i = 0; i < _chunkList.size(); i++)
87 X* chunk = _chunkList[i];
88 long adrmin = (long) (chunk);
91 long adrmax = (long) (chunk + _chunkSize);
94 int rank = (adrobj - adrmin) / sizeof(X);
95 int toFree = i * _chunkSize + rank;
96 _freeList[toFree] = true;
97 if (toFree < _nextFree)
100 //checkDelete(i); compactage non fait
105 // void destroy(int toFree)
107 // // no control 0<= toFree < _freeList.size()
108 // _freeList[toFree] = true;
109 // if (toFree < _nextFree)
110 // _nextFree = toFree;