delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/04/16:17:59

From: nikki AT gameboutique DOT co (nikki)
Newsgroups: comp.os.msdos.djgpp
Subject: failed malloc/callocs :(
Date: 4 May 1997 13:14:42 GMT
Organization: GameBoutique Ltd.
Lines: 40
Message-ID: <5ki242$qe8@bore.pipex.net>
NNTP-Posting-Host: www.gameboutique.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

hi, i have the following routine to check if there's enough available memory
for a malloc/calloc --

void needmem(unsigned int amount)
{
        if (_go32_dpmi_remaining_virtual_memory()<amount) {
                // not enough memory for upcoming mallocs
                closedown();            // shut down system
                exit(0);
        }
}

i then use this as follows :

        // we need 9.25 meg for screen buffers
        needmem(1024L*256*37+76800L*mult);
        if ((memory=(unsigned char *)calloc(1024L*256*37,1))==NULL) {
                closedown();
                printf("Insufficient memory to run. (allocation failed)\n");
                exit(0);
        }

this works fine on a 32 meg machine under win95 or dos (with cwsdpmi)
on a 16 meg machine it gives the insufficient memory error, despite having
plenty of memory ( 120 meg virtual, 14 meg real).

there are no other (large) memory allocations in the program, this is the only
one. so why does it fail? and how come needmem() said it would be fine?

does anyone have any suggestions as to how to improve needmem() so it always
works, and also how to make this run on a 16meg machine? 

cheers muchly,

nik


-- 
Graham Tootell           
nikki @gameboutique.com  

- Raw text -


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