63 void Resize(
size_t newSize){
67 for (
size_t i = 0; i < std::min(size, newSize); ++i) {
68 newNodes[i] = nodes[i];
73 for (
size_t i = size; i < newSize; ++i) {
74 newNodes[i].next = i + 1;
76 newNodes[i].data =
new T();
88 for (
size_t i = 0; i < size; ++i) {
89 nodes[i].next = i + 1;
91 nodes[i].data=
new T();
94 nodes[size - 1].next = -1;
97 QObjectPool(
size_t initialSize,
size_t expansionSize=0){
99 sizeStep=expansionSize;
102 for (
size_t i = 0; i < size; ++i) {
103 nodes[i].next = i + 1;
105 nodes[i].data=
new T();
118 size_t lastFreeNode = 0;
123 if (lastFreeNode==size ) {
132 Resize(size+sizeStep);
137 size_t newNodeIndex=lastFreeNode;
138 lastFreeNode = nodes[lastFreeNode].next;
140 return nodes[newNodeIndex];
142 void Free(
int nodeID){
143 nodes[nodeID].next = lastFreeNode;
144 lastFreeNode = nodeID;
147 for (
size_t i = 0; i < size; i++) {
148 nodes[i].next = i + 1;
155 for (
int i=0;i<size;++i){
157 delete nodes[i].data;
158 nodes[i].data=
nullptr;
Definition: qobjectpool.h:39
Definition: qobjectpool.h:42