knight/shared/KnightAllocator.h
author Scott Ehlert <ds@alliedmods.net>
Mon Nov 17 22:11:06 2008 -0600 (2008-11-17)
changeset 2404 b355f980a5c8
permissions -rw-r--r--
Removed debugging code from ConVarManager
     1 #ifndef _INCLUDE_KNIGHT_ALLOCATOR_H_
     2 #define _INCLUDE_KNIGHT_ALLOCATOR_H_
     3 
     4 #include <stddef.h>
     5 #include <stdlib.h>
     6 
     7 struct ke_allocator_s;
     8 typedef struct ke_allocator_s ke_allocator_t;
     9 
    10 typedef void *(*KEFN_ALLOCATOR)(ke_allocator_t *, size_t);
    11 typedef void (*KEFN_DEALLOCATOR)(ke_allocator_t *, void *);
    12 
    13 struct ke_allocator_s
    14 {
    15 	KEFN_ALLOCATOR alloc;
    16 	KEFN_DEALLOCATOR dealloc;
    17 	void *user;
    18 };
    19 
    20 inline void *operator new(size_t size, ke_allocator_t *alloc)
    21 {
    22 	return alloc->alloc(alloc, size);
    23 }
    24 
    25 inline void *operator new [](size_t size, ke_allocator_t *alloc)
    26 {
    27 	return alloc->alloc(alloc, size);
    28 }
    29 
    30 template <typename T>
    31 void ke_destroy(ke_allocator_t *alloc, T * data)
    32 {
    33 	data->~T();
    34 	alloc->dealloc(alloc, data);
    35 }
    36 
    37 #endif //_INCLUDE_KNIGHT_ALLOCATOR_H_