delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/07/20:07:53

Sender: nate AT cartsys DOT com
Message-ID: <375C5D7E.912D1C5@cartsys.com>
Date: Mon, 07 Jun 1999 17:02:06 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.10 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: malloc() problem
References: <l03130302b382017d4008@[145.98.116.75]>
Reply-To: djgpp AT delorie DOT com

Dlanor Blytkerchan wrote:
> 
> Hi all!
> 
> 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).

What does go32-v2 print out?  And what OS and DPMI server do you use?
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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