cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/08/03:02:53

X-Authentication-Warning: mail.bio.uva.nl: Host biomacI-138.bio.uva.nl [145.18.167.138] claimed to be [145.18.167.138]
Message-Id: <v01540b01b3826f4b700d@[145.18.167.138]>
Mime-Version: 1.0
Date: Tue, 8 Jun 1999 09:02:49 +0200
To: djgpp AT delorie DOT com
From: dlanor AT dds DOT nl (Dlanor Blytkerchan)
Subject: Re: malloc() problem
Reply-To: djgpp AT delorie DOT com

>> Here's a weird little problem: when I try to allocate a buffer with
>> malloc(), it returns NULL. The buffer I am trying to allocate is just under
>> 34K, and I have at least 4 MB free (probably much more), and at least 400K
>> in low memory. This happens regardless of where I do it (inside or outside
>> of RHIDE) and regardless of anything I do that the FAQ suggests. Even
>> directly calling that heap extender thingy as described in FAQ chaper 15 (I
>> forgot the name) returns -1 (probably why I'm getting NULL back from
>> malloc()).
>> The line I'm using is this:
>>
>> bufferType *buffer;
>> bool rc = true;
>>
>> rc = ((buffer = (bufferType*)malloc(sizeof(bufferType))) != NULL);
>> if (!rc) {
>>   start complaining and quit..
>> } // if
>>
>> Does anyone have a better way of allocating memory than this & is there
>> something I'm missing/overlooking here, or is this particular piece of
>> coding simply jynxed and should I simply retype it?
>
>Should be right (though something like `buffer = malloc(n); if (!buffer)
>die();' is a bit easier to follow).
Possibly, but not the way I generally program: rc is a global variable. If
set to false, no I/O is done any more, the problem is reported as soon as
the program is back at it's core and then dies.

>What does go32-v2 print out?  And what OS and DPMI server do you use?
The above memory value (the 4 MB) is taken from go32-v2, the 400 K from
mem, and the 34 K from sizeof().
I think I checked this quite thouroughly - I just can't find the problem so
I decided to post a message and go to sleep - it was 1 am ;-)

Greetz!

Dlanor


- Raw text -


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