Solved

Handling of memory allocation failures

Posted on 2000-04-01
5
304 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

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 99
Hibernate methods 2 87
noX challenge 17 144
Adjust the codes 3 63
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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