DevShiftTeam / AppShift-MemoryPool

A very fast cross-platform memory pool mechanism for C++ built using a data-oriented approach (3 to 24 times faster than regular new or delete, depending on operating system & compiler)
Apache License 2.0
215 stars 25 forks source link

new does not return null #5

Closed pwc357 closed 3 years ago

pwc357 commented 3 years ago

This code is wrong:

CPPShift::Memory::MemoryPool* CPPShift::Memory::MemoryPoolManager::create(size_t block_size) { // Create memory pool MemoryPool* mp = new MemoryPool; if (mp == NULL) throw EMemoryErrors::CANNOT_CREATE_MEMORY_POOL; By default, the call to new MemoryPool will never return null. You should either call malloc like you do in createMemoryBlock (recommended) or catch(std::bad_alloc).

LessComplexity commented 3 years ago

Thanks for the comment, just fixed it to use malloc instead! :)