godot_voxel/storage/voxel_memory_pool.h
Marc Gilleron 026c14fcb5 Added importer to import vox files into a single mesh
- New importer, needs restart to switch but it's a limitation of Godot
- Might blow up if the scene spans a really big area, may be optimized in the future.
- The scene importer remains the default choice
- Promoted some ints to 64-bit to avoid oveflowing with large volumes or distances
- Handle a few cases of malloc failure
2021-08-14 16:49:46 +01:00

43 lines
854 B
C++

#ifndef VOXEL_MEMORY_POOL_H
#define VOXEL_MEMORY_POOL_H
#include "core/hash_map.h"
#include "core/os/mutex.h"
#include <vector>
// Pool based on a scenario where allocated blocks are often the same size.
// A pool of blocks is assigned for each size.
class VoxelMemoryPool {
private:
struct Pool {
std::vector<uint8_t *> blocks;
};
public:
static void create_singleton();
static void destroy_singleton();
static VoxelMemoryPool *get_singleton();
VoxelMemoryPool();
~VoxelMemoryPool();
uint8_t *allocate(size_t size);
void recycle(uint8_t *block, size_t size);
void clear_unused_blocks();
void debug_print();
unsigned int debug_get_used_blocks() const;
private:
Pool *get_or_create_pool(size_t size);
void clear();
HashMap<size_t, Pool *> _pools;
unsigned int _used_blocks = 0;
Mutex _mutex;
};
#endif // VOXEL_MEMORY_POOL_H