graceful degradation: allocate fewer structs if cannot get requested amount

This commit is contained in:
ceriel 1990-01-16 14:38:28 +00:00
parent b254b73745
commit 2b6d2c8407
2 changed files with 12 additions and 3 deletions

View file

@ -20,7 +20,12 @@ st_alloc(phead, size, count)
char *retval; char *retval;
if (*phead == 0) { 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; ((_PALLOC_) p)->_A_next = 0;
while (--count) { while (--count) {
p += size; p += size;

View file

@ -19,8 +19,12 @@ std_alloc(phead, size, count, pcnt)
register char *p; register char *p;
if (*phead == 0) { if (*phead == 0) {
while (count >= 1 && (p = malloc(size * count)) == 0) {
p = Malloc(size * count); count >>= 1;
}
if (p == 0) {
No_Mem();
}
*pcnt += count; *pcnt += count;
((_PALLOC_) p)->_A_next = 0; ((_PALLOC_) p)->_A_next = 0;
while (--count) { while (--count) {