Coexistence of std_new and MFC in winx

Source: Internet
Author: User

This article has been migrated to: http://cpp.winxgui.com/cn:std-new-conflict-with-mfc

Coexistence of std_new and MFC in winx

Xu Shiwei (copyright statement)
2007-3-8

Cause

Winx's autofreealloc has received a wide range of attention, and many readers are inspired by this reaction.

Yesterday, some readers reported that std_new and MFC cannot coexist. I would like to discuss this question here.

Cause

The following debugging code is generated in the source code file:

# Ifdef _ debug
# Define new debug_new
# UNDEF this_file
Static char this_file [] = _ file __;
# Endif

A macro named new is defined here. This makes it impossible to use all non-standard new operators in the MFC program. This is a defect of MFC.

Std_new uses placement new, which is defined in the header file of the C ++ standard library <New> or <new. h>.

Solution

The recommended solution is to delete the following statements in the debugging code of the MFC in the source code file:

# Define new debug_new

However, this brings about another problem. The MFC program cannot detect the memory leakage in the source code file.

It is also very easy to solve this problem. If you want to use new, use debug_new instead. For example:

Type * A = new type (arg1, arg2 );

Change

Type * A = debug_new type (arg1, arg2 );

Personal recommendations

My personal recommendation is not only to use std_new of winx, but to use debug_new in all code, rather than using new directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.