1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-11 16:33:35 +00:00
lovr/src/math/pool.h
bjorn 7338c82d7f Add resizable vector pools;
It seems too dangerous/annoying to have pools error when they run
out of memory.  Instead, we'll make it so you can choose to make
a pool resizable, where it enlarges its memory if it runs out. By
default Pools aren't resizable, but the default math pool is.

Also, reduce the size of the default pool from 640k to 4k.
2019-01-10 14:10:04 -08:00

38 lines
857 B
C

#include "util.h"
#include <stdbool.h>
#define POOL_ALIGN 16
#define DEFAULT_POOL_SIZE (640 * 1024)
#pragma once
typedef enum {
MATH_VEC3,
MATH_QUAT,
MATH_MAT4,
MAX_MATH_TYPES
} MathType;
typedef struct {
Ref ref;
float* data;
size_t size;
size_t usage;
uint8_t* head;
bool resizable;
} Pool;
Pool* lovrPoolInit(Pool* pool, size_t size, bool resizable);
#define lovrPoolCreate(...) lovrPoolInit(lovrAlloc(Pool), __VA_ARGS__)
void lovrPoolDestroy(void* ref);
float* lovrPoolAllocate(Pool* pool, MathType type);
void lovrPoolDrain(Pool* pool);
size_t lovrPoolGetSize(Pool* pool);
size_t lovrPoolGetUsage(Pool* pool);
bool lovrPoolIsResizable(Pool* pool);
// For you, LuaJIT
LOVR_EXPORT float* lovrPoolAllocateVec3(Pool* pool);
LOVR_EXPORT float* lovrPoolAllocateQuat(Pool* pool);
LOVR_EXPORT float* lovrPoolAllocateMat4(Pool* pool);