graceful degradation: allocate fewer structs if cannot get requested amount
This commit is contained in:
parent
b254b73745
commit
2b6d2c8407
|
@ -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;
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue