Skip to content

Commit

Permalink
xrCore/xrPool.h: a bit of refactor and reformatting
Browse files Browse the repository at this point in the history
Used range-based for
  • Loading branch information
Xottab-DUTY committed Jan 6, 2018
1 parent f25a1be commit 9e1508a
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/xrCore/xrPool.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#pragma once
#ifndef xrPoolH
#define xrPoolH
#include "_types.h"
#include "xrDebug_macros.h"
//#include "_stl_extensions.h"

template <class T, int granularity>
class poolSS
{
private:
T* list;
xr_vector<T*> blocks;

private:
T** access(T* P) { return (T**)LPVOID(P); }
void block_create()
{
// Allocate
VERIFY(0 == list);
VERIFY(nullptr == list);
list = xr_alloc<T>(granularity);
blocks.push_back(list);

Expand All @@ -27,15 +21,15 @@ class poolSS
T* E = list + it;
*access(E) = E + 1;
}
*access(list + granularity - 1) = NULL;
*access(list + granularity - 1) = nullptr;
}

public:
poolSS() { list = 0; }
poolSS() : list(nullptr) {}
~poolSS()
{
for (u32 b = 0; b < blocks.size(); b++)
xr_free(blocks[b]);
for (auto& block : blocks)
xr_free(block);
}
T* create()
{
Expand All @@ -51,14 +45,13 @@ class poolSS
P->~T();
*access(P) = list;
list = P;
P = NULL;
P = nullptr;
}
void clear()
{
list = 0;
for (u32 b = 0; b < blocks.size(); b++)
xr_free(blocks[b]);
list = nullptr;
for (auto& block : blocks)
xr_free(block);
blocks.clear();
}
};
#endif

0 comments on commit 9e1508a

Please sign in to comment.