2015-04-06 16:41:33 -05:00
// 4 december 2014
2015-04-06 23:26:27 -05:00
# include "uipriv_windows.h"
2015-04-06 16:41:33 -05:00
// wrappers for allocator of choice
// panics on memory exhausted, undefined on heap corruption or other unreliably-detected malady (see http://stackoverflow.com/questions/28761680/is-there-a-windows-api-memory-allocator-deallocator-i-can-use-that-will-just-giv)
// new memory is set to zero
// passing NULL to tableRealloc() acts like tableAlloc()
// passing NULL to tableFree() is a no-op
2015-04-07 22:40:18 -05:00
void * uiAlloc ( size_t size , const char * type )
2015-04-06 16:41:33 -05:00
{
void * out ;
out = malloc ( size ) ;
if ( out = = NULL )
abort ( ) ; // TODO figure this part out
ZeroMemory ( out , size ) ;
2015-04-07 22:40:18 -05:00
# ifdef uiLogAllocations
fprintf ( stderr , " %p alloc %s \n " , out , type ) ;
# endif
2015-04-06 16:41:33 -05:00
return out ;
}
2015-04-07 22:40:18 -05:00
void * uiRealloc ( void * p , size_t size , const char * type )
2015-04-06 16:41:33 -05:00
{
void * out ;
if ( p = = NULL )
2015-04-07 22:40:18 -05:00
return uiAlloc ( size , type ) ;
2015-04-06 16:41:33 -05:00
out = realloc ( p , size ) ;
if ( out = = NULL )
abort ( ) ;
// TODO zero the extra memory
2015-04-07 22:40:18 -05:00
# ifdef uiLogAllocations
fprintf ( stderr , " %p realloc %p \n " , p , out ) ;
# endif
2015-04-06 16:41:33 -05:00
return out ;
}
void uiFree ( void * p )
{
if ( p = = NULL )
return ;
free ( p ) ;
2015-04-07 22:40:18 -05:00
# ifdef uiLogAllocations
fprintf ( stderr , " %p free \n " , p ) ;
# endif
2015-04-06 16:41:33 -05:00
}