changeset 53:dad7faa96eea

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Sep 2011 05:44:46 +0300
parents 29a5fac5c75f
children dd94096a7fcd
files src/memory.cc
diffstat 1 files changed, 20 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- 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 */