mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 21:43:34 +00:00
Merge pull request #724 from jmiskovic/fix/vector_pool_allocation
Use virtual memory in vector pools
This commit is contained in:
commit
07ff7412df
|
@ -1,5 +1,6 @@
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "core/maf.h"
|
#include "core/maf.h"
|
||||||
|
#include "core/os.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "lib/noise/simplexnoise1234.h"
|
#include "lib/noise/simplexnoise1234.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -229,21 +230,22 @@ Pool* lovrPoolCreate(void) {
|
||||||
Pool* pool = calloc(1, sizeof(Pool));
|
Pool* pool = calloc(1, sizeof(Pool));
|
||||||
lovrAssert(pool, "Out of memory");
|
lovrAssert(pool, "Out of memory");
|
||||||
pool->ref = 1;
|
pool->ref = 1;
|
||||||
|
pool->data = os_vm_init((1 << 24) * sizeof(float));
|
||||||
lovrPoolGrow(pool, 1 << 12);
|
lovrPoolGrow(pool, 1 << 12);
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrPoolDestroy(void* ref) {
|
void lovrPoolDestroy(void* ref) {
|
||||||
Pool* pool = ref;
|
Pool* pool = ref;
|
||||||
free(pool->data);
|
os_vm_free(pool->data, (1 << 24) * sizeof(float));
|
||||||
free(pool);
|
free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrPoolGrow(Pool* pool, size_t count) {
|
void lovrPoolGrow(Pool* pool, size_t count) {
|
||||||
lovrAssert(count <= (1 << 24), "Temporary vector space exhausted. Try using lovr.math.drain to drain the vector pool periodically.");
|
lovrAssert(count <= (1 << 24), "Temporary vector space exhausted. Try using lovr.math.drain to drain the vector pool periodically.");
|
||||||
pool->count = (uint32_t) count; // Assert guarantees safe
|
pool->count = (uint32_t) count; // Assert guarantees safe
|
||||||
pool->data = realloc(pool->data, pool->count * sizeof(float));
|
bool result = os_vm_commit(pool->data, count * sizeof(float));
|
||||||
lovrAssert(pool->data, "Out of memory");
|
lovrAssert(result, "Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector lovrPoolAllocate(Pool* pool, VectorType type, float** data) {
|
Vector lovrPoolAllocate(Pool* pool, VectorType type, float** data) {
|
||||||
|
|
Loading…
Reference in a new issue