vector의 표준을 살펴보면 두번째 인자로 default값이 있는 allocator를 할당 받는다.
먼저 만들어둔 allocator를 매개변수로 넣고 실행하면 오류가 난다.
vector<int32, BaseAllocator> v;
요구하는 형식에 맞춰 alloactor를 만들어 보도록 하자
// Allocator.h
template<typename T>
class STLAllocator
{
public:
using value_type = T;
STLAllocator() {}
template<typename Other>
STLAllocator(const STLAllocator<Other>&) {}
T* allocate(size_t count)
{
const int32 size = static_cast<int32>(count * sizeof(T));
return static_cast<T*>(Xalloc(size));
}
void deallocate(T* ptr, size_t count)
{
Xrelease(ptr);
}
};
코드)
https://github.com/Juzdalua/Study-Cpp-Server/blob/master/ServerCore/Container.h
Study-Cpp-Server/ServerCore/Container.h at master · Juzdalua/Study-Cpp-Server
Study C++ IOCP. Contribute to Juzdalua/Study-Cpp-Server development by creating an account on GitHub.
github.com
'Server > C++' 카테고리의 다른 글
TypeCase (0) | 2024.08.06 |
---|---|
메모리 풀링 (0) | 2024.08.05 |
메모리 오염과 Stomp Allocator (0) | 2024.08.05 |
가상메모리 (0) | 2024.08.05 |
커스텀 메모리 할당 - Custom new & delete (0) | 2024.08.04 |