Adapt interface:wq
This commit is contained in:
@@ -45,19 +45,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <stddef.h>
|
||||
|
||||
typedef void* (*alloc_func)(size_t size);
|
||||
typedef void* (*realloc_func)(void* ptr, size_t size);
|
||||
typedef void (*free_func)(void* ptr);
|
||||
|
||||
struct Allocator {
|
||||
alloc_func alloc{nullptr};
|
||||
realloc_func realloc{nullptr};
|
||||
free_func free{nullptr};
|
||||
static alloc_func alloc{nullptr};
|
||||
static free_func free{nullptr};
|
||||
|
||||
static void init(alloc_func alloc_fn, free_func free_fn) {
|
||||
alloc = alloc_fn;
|
||||
free = free_fn;
|
||||
}
|
||||
};
|
||||
|
||||
static void aiRegisterAllocator(alloc_func alloc_fn, free_func free_fn) {
|
||||
Allocator::init(alloc_fn, free_fn);
|
||||
}
|
||||
|
||||
#define AI_NEW(ai_type,...) new ai_type(__VA_ARGS__)
|
||||
#define AI_NEW_ARRAY(ai_type,count) new ai_type[count]()
|
||||
#define AI_DELETE(ptr) delete ptr
|
||||
#define AI_DELETE_ARRAY(ptr) delete[] ptr
|
||||
|
||||
#endif // AI_ALLOCATOR_H_INC
|
||||
|
||||
|
||||
Reference in New Issue
Block a user