27 void setBufferSize(
unsigned int BufferSize){
29 m_BufferSize = BufferSize;
30 m_sizeConvergenceCounter = BufferSize;
35 unsigned int getObjectCounter(){
36 return m_ObjectCounter;
44 m_sizeConvergenceCounter = m_ObjectCounter >= m_sizeConvergenceCounter ? m_ObjectCounter : (m_sizeConvergenceCounter+m_ObjectCounter)/2;
45 if(m_sizeConvergenceCounter < (m_buffers.size()-1)*m_BufferSize){
48 m_currentBuffer = m_buffers.begin();
50 m_currentBufferIndex = 0;
53 _ObjectType_* getNewObject(){
55 if(m_currentBufferIndex >= m_BufferSize){
56 m_currentBufferIndex = 0;
57 if(++m_currentBuffer == m_buffers.end())
60 return static_cast<_ObjectType_*
>(*m_currentBuffer) + (m_currentBufferIndex++);
63 _ObjectType_* getNewObjectThreadSafe(){
64 std::scoped_lock lock(m_Lock);
65 return getNewObject();
72 void createNewBuffer(){
73 m_currentBufferIndex = 0;
76 _ObjectType_* buffer =
new _ObjectType_[m_BufferSize];
77 m_buffers.push_back(buffer);
78 m_currentBuffer = m_buffers.end();
81 catch (
const std::bad_alloc& error)
83 std::cerr <<
"ERROR: Bad memory allocation in ObjectFactoryStack<" <<
typeid(_ObjectType_).name() <<
">" << std::endl;
84 std::cerr << error.what() << std::endl;
90 delete []
static_cast<_ObjectType_*
>(m_buffers.back());
94 void destroyAllBuffers(){
95 for(std::list<void*>::iterator i = m_buffers.begin(); i != m_buffers.end(); ++i){
96 delete []
static_cast<_ObjectType_*
>(*i);
102 unsigned int m_ObjectCounter;
103 unsigned int m_sizeConvergenceCounter;
105 unsigned int m_BufferSize;
106 std::list<void*>::iterator m_currentBuffer;
107 unsigned int m_currentBufferIndex;
108 std::list<void*> m_buffers;
Definition: ObjectFactoryStack.h:22
Definition: CollisionManager.h:6