Mail Archives: djgpp/1997/10/09/20:05:08
At 06:56 10/7/1997 GMT, Josh Rubin wrote:
>The test program below allocates blocks of 4000 bytes,
>which should fit easily in a page even with the malloc
>overhead.
>--> malloc allocates *every other* page! <--
>(the same thing happens with smaller blocks, like 3000 bytes)
>
>--------------
>#include <stdio.h>
>#include <stdlib.h>
>
>int main()
>{
> int n;
> void *p;
> for (n=0;n<10;++n) {
> p = malloc(4000); /* should fit in 1 page, even with overhead
>*/
> printf(" %x\n",(int)p);
> }
> return 0;
>}
printf() uses malloc. This may be skewing your results. DJGPP's malloc() is
known to be rather wasteful; memory is traded off for speed. You could
always look at the malloc sources if you really want to know why.
Nate Eldredge
eldredge AT ap DOT net
- Raw text -