# HG changeset patch # User Matti Hamalainen # Date 1317005086 -10800 # Node ID dad7faa96eeadae9ea81fd31497e04a671a906ed # Parent 29a5fac5c75fae5094ee7f048982bcdb7551a1cd Cleanups. diff -r 29a5fac5c75f -r dad7faa96eea src/memory.cc --- a/src/memory.cc Mon Sep 26 04:40:25 2011 +0300 +++ b/src/memory.cc Mon Sep 26 05:44:46 2011 +0300 @@ -44,77 +44,53 @@ about memory fragmentation. */ -#define SIZE_THRESHOLD 1024 +#define SIZE_THRESHOLD 1024 #define SIZE_OF_BLOCK 4095 /* actually, this is (size - 1) */ /* - allocate memory with error checking -*/ - + * Allocate memory with error checking + */ void *GetMemory(unsigned long size) { void *ret; -/* On 16-bit systems (BC 4.0), size_t is only 16-bit long so - you can't malloc() more than 64 kB at a time. Catch it. */ - if (size != (size_t) size) - fatal_error("GetMemory: %lu B is too much for this poor machine.", - size); - -/* limit fragmentation on large blocks */ + /* Limit fragmentation on large blocks */ if (size >= SIZE_THRESHOLD) size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; - ret = malloc((size_t) size); - if (!ret) - { - /* retry after having freed some memory, if possible */ - ret = malloc((size_t) size); - } - if (!ret) + + ret = malloc(size); + if (ret == NULL) fatal_error("out of memory (cannot allocate %u bytes)", size); + return ret; } /* - reallocate memory with error checking -*/ - + * Reallocate memory with error checking + */ void *ResizeMemory(void *old, unsigned long size) { void *ret; -/* On 16-bit systems (BC 4.0), size_t is only 16-bit long so - you can't malloc() more than 64 kB at a time. Catch it. */ - if (size != (size_t) size) - fatal_error("ResizeMemory: %lu B is too much for this poor machine.", - size); - -/* limit fragmentation on large blocks */ + /* Limit fragmentation on large blocks */ if (size >= SIZE_THRESHOLD) size = (size + SIZE_OF_BLOCK) & ~SIZE_OF_BLOCK; - ret = realloc(old, (size_t) size); - if (!ret) - { - ret = realloc(old, (size_t) size); - } - if (!ret) - fatal_error("out of memory (cannot reallocate %lu bytes)", size); + + ret = realloc(old, size); + if (ret == NULL) + fatal_error("Out of memory (cannot reallocate %lu bytes)", size); + return ret; } /* - free memory -*/ - + * Free memory + */ void FreeMemory(void *ptr) { -/* just a wrapper around free(), but provide an entry point */ -/* for memory debugging routines... */ - free(ptr); + if (ptr != NULL) + free(ptr); } - - -/* end of file */