delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/09/20:05:08

Date: Thu, 9 Oct 1997 17:03:28 -0700 (PDT)
Message-Id: <199710100003.RAA14872@adit.ap.net>
Mime-Version: 1.0
To: jlrubin AT NO_MEAT_BYPRODUCTS DOT bway DOT net (Josh Rubin), djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Why is malloc allocating every other page?

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019