delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/30/10:55:51

Date: Sun, 30 Aug 1998 17:55:07 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Klaus Petzold <califax AT wupperonline DOT de>
cc: djgpp AT delorie DOT com
Subject: Re: Strange results with own maxheapblock()-function
In-Reply-To: <35e71d68.66941@news.space.net>
Message-ID: <Pine.SUN.3.91.980830175043.20257n@is>
MIME-Version: 1.0

On Fri, 28 Aug 1998, Klaus Petzold wrote:

> I tried to write a function, which finds out the size of the largest
> block I can allocate on the heap. On my system it gives back
> 33558524 bytes, but with "char* ptr = (char *)malloc(size);" it
> is possible to allocate 67112956 bytes. Has anyone an idea why
> maxheapblock() fails?

I suggest to read chapter 15 in general, and sections 15.2 and 15.4 in 
particular, from the DJGPP FAQ list, before you plunge into this mess.  
Several subtle points are explained there.

>       do
>       {
>          memsize += adder;
> 
>          cptr = (char *)malloc(memsize);
>          free(cptr);
>       } while (cptr);

`malloc' adds some overhead to the size you request, and then rounds it 
up to the next integral power of 2.  So you actually ask the DPMI server 
for much more than you intend to.

- Raw text -


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