graceful degradation: allocate fewer structs if cannot get requested amount
authorceriel <none@none>
Tue, 16 Jan 1990 14:38:28 +0000 (14:38 +0000)
committerceriel <none@none>
Tue, 16 Jan 1990 14:38:28 +0000 (14:38 +0000)
modules/src/alloc/st_alloc.c
modules/src/alloc/std_alloc.c

index 8ead244..b8c6927 100644 (file)
@@ -20,7 +20,12 @@ st_alloc(phead, size, count)
        char *retval;
 
        if (*phead == 0)        {
-               p = Malloc(size * count);
+               while (count >= 1 && (p = malloc(size * count)) == 0) {
+                       count >>= 1;
+               }
+               if (p == 0) {
+                       No_Mem();
+               }
                ((_PALLOC_) p)->_A_next = 0;
                while (--count) {
                        p += size;
index 334581c..381ba40 100644 (file)
@@ -19,8 +19,12 @@ std_alloc(phead, size, count, pcnt)
        register char *p;
 
        if (*phead == 0)        {
-
-               p = Malloc(size * count);
+               while (count >= 1 && (p = malloc(size * count)) == 0) {
+                       count >>= 1;
+               }
+               if (p == 0) {
+                       No_Mem();
+               }
                *pcnt += count;
                ((_PALLOC_) p)->_A_next = 0;
                while (--count) {