mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-07 09:26:01 +01:00
d24961db15
The intent is to manage long-vs-single-frame allocations better. Previously long allocations were map-long bump allocations, and couldn't be freed mid-map, as there was neither a reference to the allocated range, nor a way to actully free it. Add a two-mode block allocator (similar to previous debuffer alloc) that allows making long and once allocations. But now long allocations are backed by "pool" allocator and return references to the range. This commit doesn't do the deallocation yet, so map chaning doesn't yet work.
52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#pragma once
|
|
#include <stdint.h>
|
|
|
|
typedef uint32_t alo_size_t;
|
|
|
|
struct alo_pool_s;
|
|
|
|
struct alo_pool_s* aloPoolCreate(alo_size_t size, int expected_allocations, alo_size_t min_alignment);
|
|
void aloPoolDestroy(struct alo_pool_s*);
|
|
|
|
typedef struct {
|
|
alo_size_t offset;
|
|
alo_size_t size;
|
|
|
|
int index;
|
|
} alo_block_t;
|
|
|
|
alo_block_t aloPoolAllocate(struct alo_pool_s*, alo_size_t size, alo_size_t alignment);
|
|
void aloPoolFree(struct alo_pool_s *pool, int index);
|
|
|
|
// <- size ->
|
|
// [.....|AAAAAAAAAAAAAAA|......]
|
|
// ^ -- tail ^ -- head
|
|
typedef struct {
|
|
uint32_t size, head, tail;
|
|
} alo_ring_t;
|
|
|
|
#define ALO_ALLOC_FAILED 0xffffffffu
|
|
|
|
// Marks the entire buffer as free
|
|
void aloRingInit(alo_ring_t* ring, uint32_t size);
|
|
|
|
// Allocates a new aligned region and returns offset to it (AllocFailed if allocation failed)
|
|
uint32_t aloRingAlloc(alo_ring_t* ring, uint32_t size, uint32_t alignment);
|
|
|
|
// Marks everything up-to-pos as free (expects up-to-pos to be valid)
|
|
void aloRingFree(alo_ring_t* ring, uint32_t up_to_pos);
|
|
|
|
// Integer pool/freelist
|
|
// Get integers from 0 to capacity
|
|
typedef struct alo_int_pool_s {
|
|
int *free_list;
|
|
int capacity;
|
|
int free;
|
|
} alo_int_pool_t;
|
|
|
|
void aloIntPoolGrow(alo_int_pool_t *pool, int new_capacity);
|
|
int aloIntPoolAlloc(alo_int_pool_t *pool);
|
|
void aloIntPoolFree(alo_int_pool_t *pool, int);
|
|
void aloIntPoolClear(alo_int_pool_t *pool);
|
|
void aloIntPoolDestroy(alo_int_pool_t *pool);
|