Date: Thu, 9 Oct 1997 17:03:28 -0700 (PDT) Message-Id: <199710100003.RAA14872@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: jlrubin AT NO_MEAT_BYPRODUCTS DOT bway DOT net (Josh Rubin), djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Why is malloc allocating every other page? Precedence: bulk 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 >#include > >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