dvander@2226: #ifndef _INCLUDE_KNIGHT_ALLOCATOR_H_ dvander@2226: #define _INCLUDE_KNIGHT_ALLOCATOR_H_ dvander@2226: dvander@2226: #include dvander@2226: #include dvander@2226: dvander@2226: struct ke_allocator_s; dvander@2226: typedef struct ke_allocator_s ke_allocator_t; dvander@2226: dvander@2226: typedef void *(*KEFN_ALLOCATOR)(ke_allocator_t *, size_t); dvander@2226: typedef void (*KEFN_DEALLOCATOR)(ke_allocator_t *, void *); dvander@2226: dvander@2226: struct ke_allocator_s dvander@2226: { dvander@2226: KEFN_ALLOCATOR alloc; dvander@2226: KEFN_DEALLOCATOR dealloc; dvander@2226: void *user; dvander@2226: }; dvander@2226: dvander@2226: inline void *operator new(size_t size, ke_allocator_t *alloc) dvander@2226: { dvander@2226: return alloc->alloc(alloc, size); dvander@2226: } dvander@2226: dvander@2226: inline void *operator new [](size_t size, ke_allocator_t *alloc) dvander@2226: { dvander@2226: return alloc->alloc(alloc, size); dvander@2226: } dvander@2226: dvander@2226: template dvander@2226: void ke_destroy(ke_allocator_t *alloc, T * data) dvander@2226: { dvander@2226: data->~T(); dvander@2226: alloc->dealloc(alloc, data); dvander@2226: } dvander@2226: dvander@2226: #endif //_INCLUDE_KNIGHT_ALLOCATOR_H_