Line data Source code
1 : // Internal Includes 2 : #include "kirke/system_allocator.h" 3 : 4 : // System Includes 5 : #include <stdlib.h> 6 : 7 : // Internal Includes 8 : #include "kirke/system_allocator.h" 9 : 10 89 : static void* system_allocator__alloc( unsigned long long size, void* allocator_data ){ 11 : (void)( allocator_data ); 12 89 : return malloc( size ); 13 : } 14 : 15 42 : static void* system_allocator__realloc( void* pointer, unsigned long long size, void* allocator_data ){ 16 : (void)( allocator_data ); 17 42 : return realloc( pointer, size ); 18 : } 19 : 20 78 : static void system_allocator__free( void* pointer, void* allocator_data ){ 21 : (void)( allocator_data ); 22 78 : free( pointer ); 23 78 : } 24 : 25 0 : static void system_allocator__out_of_memory( void* allocator_data ){ 26 0 : SystemAllocator* system_allocator = (SystemAllocator*) allocator_data; 27 : 28 0 : if( system_allocator->out_of_memory_callback != NULL ){ 29 0 : system_allocator->out_of_memory_callback(); 30 : } 31 0 : } 32 : 33 33 : void system_allocator__initialize( SystemAllocator* system_allocator, void( *out_of_memory_callback )( void ) ){ 34 33 : system_allocator->allocator = allocator__create( 35 : system_allocator__alloc, 36 : system_allocator__realloc, 37 : system_allocator__free, 38 : system_allocator__out_of_memory, 39 : system_allocator 40 : ); 41 : 42 33 : system_allocator->out_of_memory_callback = out_of_memory_callback; 43 33 : } 44 : 45 33 : void system_allocator__deinitialize( SystemAllocator* system_allocator ){ 46 33 : if( system_allocator != NULL ){ 47 33 : allocator__destroy( system_allocator->allocator ); 48 33 : system_allocator->out_of_memory_callback = NULL; 49 : } 50 33 : }