Try to allocate to the next power of 2, instead of just aligning

with GRABSIZE; This way, malloc(1000000) followed by free() followed by
another malloc(1000000) will result in the same block being allocated,
because first_present will now find it
This commit is contained in:
ceriel 1989-02-10 09:18:19 +00:00
parent 7161d59956
commit 5a4933ff7f

View file

@ -67,10 +67,10 @@ malloc(n)
assert(n1 < (1 << LOG_MAX_SIZE)); assert(n1 < (1 << LOG_MAX_SIZE));
min_class = 0; min_class = 0;
while (n1 >= MIN_SIZE) { do {
n1 >>= 1; n1 >>= 1;
min_class++; min_class++;
} } while (n1 >= MIN_SIZE);
} }
if (min_class >= MAX_FLIST) if (min_class >= MAX_FLIST)
@ -81,7 +81,8 @@ malloc(n)
register char *p; register char *p;
#define GRABSIZE 4096 /* Power of 2 */ #define GRABSIZE 4096 /* Power of 2 */
register unsigned int req = register unsigned int req =
(n+mallink_size()+GRABSIZE-1)&~(GRABSIZE-1); ((MIN_SIZE<<min_class)+ mallink_size() + GRABSIZE - 1) &
~(GRABSIZE-1);
if (!ml_last) { if (!ml_last) {
/* first align SBRK() */ /* first align SBRK() */