]> git.tdb.fi Git - libs/game.git/commitdiff
Use different allocation functions for pools
authorMikko Rasa <tdb@tdb.fi>
Sun, 26 Jan 2025 20:47:12 +0000 (22:47 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 27 Jan 2025 11:28:31 +0000 (13:28 +0200)
It appears using alignas with new is a gcc extension.

source/game/pool.cpp

index a986302e3433c6157772b0ca5c5ae206db12e704..d53a2e0412f4306746ac857c665a0dbd278b9a68 100644 (file)
@@ -80,8 +80,8 @@ void PoolBase::destroy_all()
 
        unsigned block_count = capacity/BLOCK_SIZE;
        for(unsigned i=0; i<block_count; ++i)
-               delete[] blocks[i];
-       delete[] reinterpret_cast<char *>(blocks);
+               ::operator delete(blocks[i]);
+       ::operator delete(blocks);
 }
 
 void *PoolBase::prepare_allocate()
@@ -116,14 +116,16 @@ void PoolBase::commit_allocate(void *ptr)
 void PoolBase::add_block()
 {
        unsigned block_count = capacity/BLOCK_SIZE;
-       char *new_mem = new alignas(char *) char[(block_count+1)*(sizeof(char *)+BLOCK_SIZE*sizeof(uint32_t))];
+       size_t meta_size = (block_count+1)*(sizeof(char *)+BLOCK_SIZE*sizeof(uint32_t));
+       char *new_mem = static_cast<char *>(::operator new(meta_size, static_cast<align_val_t>(alignof(char *))));
        char **new_blocks = reinterpret_cast<char **>(new_mem);
        uint32_t *new_free = reinterpret_cast<uint32_t *>(new_mem+(block_count+1)*sizeof(char *));
 
        copy(blocks, blocks+block_count, new_blocks);
        copy(free_list, free_list+capacity, new_free);
 
-       char *block = new alignas(BLOCK_ALIGNMENT) char[BLOCK_SIZE*object_size+BLOCK_SIZE/8];
+       size_t storage_size = BLOCK_SIZE*object_size+BLOCK_SIZE/8;
+       char *block = static_cast<char *>(::operator new(storage_size, static_cast<align_val_t>(BLOCK_ALIGNMENT)));
        new_blocks[block_count] = block;
        FlagType *flags = reinterpret_cast<FlagType *>(block+BLOCK_SIZE*object_size);
        for(unsigned i=0; i<BLOCK_SIZE; ++i)
@@ -131,7 +133,7 @@ void PoolBase::add_block()
        for(unsigned i=0; i<BLOCK_SIZE/FLAG_BITS; ++i)
                flags[i] = 0;
 
-       delete[] reinterpret_cast<char *>(blocks);
+       ::operator delete(blocks);
        blocks = new_blocks;
        free_list = new_free;
        capacity += BLOCK_SIZE;