delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/23/13:00:30

From: "Rafał Maj" <r_maj AT poczta DOT onet DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: memory reserve !!!!!!!!!!!!!!!!!!!!
Date: Wed, 23 Aug 2000 16:32:47 +0200
Organization: Academic Computer Center CYFRONET AGH
Lines: 50
Message-ID: <8o0n79$su$1@info.cyf-kr.edu.pl>
NNTP-Posting-Host: d-94-53-25.cyfronet.krakow.pl
X-Trace: info.cyf-kr.edu.pl 967041065 926 149.156.1.185 (23 Aug 2000 14:31:05 GMT)
X-Complaints-To: news AT cyf-kr DOT edu DOT pl
NNTP-Posting-Date: 23 Aug 2000 14:31:05 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

In my program I allocate all memory like this :

    MyClass *ptr;
    try { ptr = new MyClass( var1, var2); }
    catch (std::bad_alloc) { cMemoryManager->needed( sizeof(MyClass) ); }
    // thanks to drew AT Poohstick DOT ORG

where cMemoryManager->needed(long SIZE) is function, with unloads SIZE bytes
of data from memory.

So now everything is fine - when program runs out of virtual memory, it
automaticly unloads unnessesary data.

BUT : some other functions (for example from libraries) are still allocating
memory in old way - just using  new. So when out-of-memory-error wil occur
in library function (and not in my program) then ofcourse my
cMemoryManager->needed function won't be called and program will crash.

===========================
So I want  new() operator to throw exceptions, not only when all memory is
used, but
when free memory is less then, for example 32Kb.
HOW CAN I DO THIS ???

1) I can't use any function like _go32_dpmi_get_free_memory... because they
don't show real amount of free memory.
2)This solution :
  try { some_library_fun(); }
  catch (std::bad_alloc) { cMemoryManager->needed( 64*1024 ); }
Isn't good because it's very *not* nice & It don't help if library function
uses malloc()

==============================
3) This solution will probably work but I think it is not nice... what You
think ?

    try { ptr = new MyClass( var1, var2); }
    catch (std::bad_alloc) { cMemoryManager->needed( sizeof(MyClass) ); }
    try { *TEST = new char[reserve_size]; }
    catch (std::bad_alloc) { cMemoryManager->needed(reserve_size); }
    delete TEST;







- Raw text -


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