#pragma once
#include <list>

class Simpool
{
public:
        void* alloc()
        {
                if(this->freeList.begin() == this->freeList.end())
                {
                        return (void*)(new char[this->AllocSize]);
                }
                else
                {
                        this->freeListIter = this->freeList.begin();
                        void* ret = *(this->freeListIter);
                        this->freeList.erase(this->freeListIter);
                        return ret;
                }
        }

        void free(void* mem)
        {
                this->freeList.push_back(mem);
        }
        
        Simpool(int sz)
        {
                this->AllocSize = sz;
        }

        Simpool(int sz, int cnt)
        {
                this->AllocSize = sz;
                char* tmp = new char[sz*cnt];
                for(int i = 0; i < cnt; i++)
                {
                        this->freeList.push_back(tmp+(i*sz));
                }
        }
private:
        int AllocSize;
        std::list<void*> freeList;
        std::list<void*>::iterator freeListIter;
};

그냥 생각나는데로 간단하게 만들어봤음...

자주 할당 / 해제 되는 특정 구조체 메모리 풀링 관리 해주는건데..

Simpool Test = new Simpool(sizeof(STRUCT));

이렇게 할당해서 Test.alloc() 하면 할당되고 Test.free(pointer) 하면 할당해제됨

할당 해제 할때 클래스에서 만들어둔 리스트에 보관을 하고... 이후에 alloc 하면 전에 할당해둔걸 그대로 반환하도록 했거든?

따로 뭐 체크한다거나... 그런거 하면 속도도 약간 느려질거고 만든 의미가 없어지는거 가틈

저런 메모리풀 어떰 ?

걍 간단하게 돌아가는것만 확인했는데 소스검증이나 이런건 어떻게 체크해보면 될가... 내가 보기엔 아직 문제업는 소스코드 같은데