?
Solved

Handling of memory allocation failures

Posted on 2000-04-01
5
Medium Priority
?
307 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

762 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