Stardew Engine
Loading...
Searching...
No Matches
ObjectPool.h
Go to the documentation of this file.
1#ifndef OBJECT_POOL_H
2#define OBJECT_POOL_H
3#ifdef __cplusplus
4extern "C"{
5#endif
6
7#include "IntTypes.h"
8
9void* InitObjectPool(int objectSize, int poolInitialSize);
10
11void* GetObjectPoolIndex(void* pObjectPool, int* pOutIndex);
12
13void FreeObjectPoolIndex(void* pObjectPool, int indexToFree);
14
15void* FreeObjectPool(void* pObjectPool);
16
25
26#define OBJECT_POOL(a) a*
27#define NEW_OBJECT_POOL(a, size) ((a*)InitObjectPool(sizeof(a),size))
28
29#define ObjectPoolCapacity(pObjectPool) ((((struct ObjectPoolData*)pObjectPool) - 1)->capacity)
30
31#define OBJ_POOL_BOUNDS_CHECK(handle, rVal, pool)\
32{\
33 bool bBoundsValid = handle < ObjectPoolCapacity(pool) && handle >= 0;\
34 if(!bBoundsValid){\
35 printf("function '%s' invalid bounds handle %i", __FUNCTION__, handle);\
36 return rVal;\
37 }\
38}
39
40#define OBJ_POOL_BOUNDS_CHECK_NO_RETURN(handle, pool)\
41{\
42 bool bBoundsValid = handle < ObjectPoolCapacity(pool) && handle >= 0;\
43 if(!bBoundsValid){\
44 printf("function '%s' invalid bounds handle %i", __FUNCTION__, handle);\
45 return;\
46 }\
47}
48
49#define ObjectPoolFreeArraySize(pObjectPool) (((struct ObjectPoolData*)pObjectPool) - 1)->freeObjectsArraySize
50
51#ifdef __cplusplus
52}
53#endif
54#endif // ! OBJECT_POOL_H
uint64_t u64
Definition IntTypes.h:15
int64_t i64
Definition IntTypes.h:16
void FreeObjectPoolIndex(void *pObjectPool, int indexToFree)
Definition ObjectPool.c:61
void * FreeObjectPool(void *pObjectPool)
Definition ObjectPool.c:80
void * InitObjectPool(int objectSize, int poolInitialSize)
Definition ObjectPool.c:10
void * GetObjectPoolIndex(void *pObjectPool, int *pOutIndex)
returns the object pool, possibly resized. returns index of a free space in the pool through pOutInde...
Definition ObjectPool.c:50
16 byte aligned
Definition ObjectPool.h:19
i64 capacity
Definition ObjectPool.h:21
u64 * freeObjectIndicessArray
Definition ObjectPool.h:23
i64 freeObjectsArraySize
Definition ObjectPool.h:22
i64 objectSize
Definition ObjectPool.h:20