mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-11 16:33:35 +00:00
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.
38 lines
857 B
C
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);
|