delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/26/12:00:43

Date: Sat, 26 Jul 1997 09:00:27 -0700 (PDT)
Message-Id: <199707261600.JAA29579@adit.ap.net>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: re: mem alloc taking up power of 2

Okay, just to further confuse this thread... ;-)
>AFAIK, allocated memory always remains purely "virtual" until it is
>actually used.
I ran this sample program:

#include <stdio.h>
#include <stdlib.h>

#define SIZE 500000 /* or anything */

int main(void)
{
   unsigned long rt = 0;
   while (malloc(SIZE) != NULL)
      printf("Have now malloced %lu bytes\n",rt += SIZE);
   return 0;
}

By the above principle, it ought to get to a very high number indeed before
stopping, since the only memory actually touched is that for malloc's
headers. However, what actually occurs is it stops after reaching an number
close to the sum of those reported by go32-v2.
Is there a logical way to reconcile the statement and the program? Have I
completely overlooked something? What really happens with malloc? How many
licks does it take to get to the Tootsie Roll center of a Tootsie Pop? :-)


Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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