File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed
Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -27,27 +27,25 @@ class RenderCommandPool
2727// {
2828// CCLOG("All RenderCommand should not be used when Pool is released!");
2929// }
30- for (typename std::list<T*>::iterator iter = _freePool.begin (); iter != _freePool.end (); ++iter)
30+ _freePool.clear ();
31+ for (typename std::list<T*>::iterator iter = _allocatedPoolBlocks.begin (); iter != _allocatedPoolBlocks.end (); ++iter)
3132 {
32- delete *iter;
33+ delete[] *iter;
3334 *iter = nullptr ;
3435 }
35- _freePool .clear ();
36+ _allocatedPoolBlocks .clear ();
3637 }
3738
3839public:
3940 T* generateCommand ()
4041 {
4142 T* result = nullptr ;
42- if (0 == _freePool.size ())
43+ if (_freePool.empty ())
4344 {
44- result = new T ();
45- }
46- else
47- {
48- result = _freePool.front ();
49- _freePool.pop_front ();
45+ AllocateCommands ();
5046 }
47+ result = _freePool.front ();
48+ _freePool.pop_front ();
5149 // _usedPool.insert(result);
5250 return result;
5351 }
@@ -64,8 +62,19 @@ class RenderCommandPool
6462 // _usedPool.erase(ptr);
6563
6664 }
67-
6865private:
66+ void AllocateCommands ()
67+ {
68+ static const int COMMANDS_ALLOCATE_BLOCK_SIZE = 32 ;
69+ T* commands = new T[COMMANDS_ALLOCATE_BLOCK_SIZE];
70+ _allocatedPoolBlocks.push_back (commands);
71+ for (int index = 0 ; index < COMMANDS_ALLOCATE_BLOCK_SIZE; ++index)
72+ {
73+ _freePool.push_back (commands+index);
74+ }
75+ }
76+ private:
77+ std::list<T*> _allocatedPoolBlocks;
6978 std::list<T*> _freePool;
7079 // std::set<T*> _usedPool;
7180};
You can’t perform that action at this time.
0 commit comments