Solved

Handling of memory allocation failures

Posted on 2000-04-01
5
305 Views
Last Modified: 2013-11-20
I just tried to set my own routine to handle memory allocation failures in
an MFC application. I used _set_new_handler function, but it did not work.
When the application ran out of memory my routine was not entered. Instead a
message "Out of memory" appeared. I guess this is some standard handling
done by MFC, however I was not able to find where it is done and how I can
change it.
0
Comment
Question by:ewajoz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:kkarunakar
ID: 2676387
Hi there ,
This is keshav from India. Plese make ur question clear.How do u use the _set_new_handler();
For giving any comment on this Pls give some code also..
Regards..keshav
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 2677211
The exception-handling function specified with the _set_new_handler function is called only if the new operator (and malloc if the _set_new_mode function specifies so) fails to allocate memory. It won't be called when Win32 API functions fail to allocate memory, such as VirtualAlloc, GlobalAlloc.
0
 
LVL 3

Expert Comment

by:Try
ID: 2677439
"chensu", OK, he found out the hard way that "_set_new_handler" does not work the way he applied it, but you forgot to tell him how "to handle memory allocation failures in an MFC application."  You only told him why it didn't work!
0
 
LVL 23

Expert Comment

by:chensu
ID: 2677893
It depends on which MFC functions are being used. In some cases, you may use try-catch to catch the CMemoryException.
0
 

Author Comment

by:ewajoz
ID: 2679259
I know that _set_new_handler does not cover API functions, I used new op.
Chensu's remark on exception throwing is right - it is my case. It is a pity you cannot find that information in MSDN in "new" description. (accoriding to it NULL is returned on allocation failure).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question