2014-11-24~11-28 Work Memo

Source: Internet
Author: User

  1. C + + new, you should use char * p = new (Std::nothrow) char[1024];

    if (p = = nullptr)

    {...}

    Otherwise, when the memory allocation fails, it throws an exception instead of returning an empty

  2. Nullptr

    In C + + it is better to use this instead of NULL (usually defined as 0, you can redefine it), on the one hand, the code is readable, marked as a pointer, on the other hand, see the following situation

    Declaration of Function 1 void f (int i, int* p);

    Declaration of Function 2 void f (int i, int p);

    Then you call F (4, NULL) probably want to call the 1th function, but sadly, you call the 2nd one. Then define

    #define NULL ((void*) 0) not? The answer is no, C + + does not allow void * variables to be assigned to other types of pointers (vice versa)

    Also, if you use a template, it may cause compilation errors. Like what

    void Test (std::p air<int*, int> p), the function, if you call the test (Std::make_pair<null, 4>) the compiler will error. Of course, a function can be converted if it defines the

    Test (int *p), call Test (0) or test (NULL), then the system is automatically converted to null pointer call above, this will not cause the compiler to error

  3. VS2010, about precompiled header files

    The settings in the project are set by default for all files that are set individually. For example, a.cpp "Using Precompiled header Files"

    If the project is not used by default, then A.cpp is using the precompiled header file alone. If you do not define stdafx.cpp at this time, you should define a stdafx.cpp,stdafx.h and specify Stdafx.cpp as "Create Precompiled Header File" (Otherwise you compile will say cannot find the. pch file), although there is no test, but I think the precompiled header file should be able to use other names, but must be guaranteed to be used to create a precompiled header file, the other for use.

    Once you have used the precompiled header file for CPP in a directory, even if the CPP is not in the same directory as the StdAfx.h, the compilation will not prompt you to find the file, because as long as your project has a. PCH, this CPP will find the appropriate information.

  4. WinDbg's command to analyze the DMP file:

    !analyze-v

  5. About help anomaly targeting

Throw an integer (specific) that can locate the exception position we can throw a specific integer where we need to throw an exception, to make it easier to find the location of the exception code when it crashes.    For example, you can define a struct exp_value{static const ULONG64 Exp_value_offset = 0xa1b2d3e4f9e80000;    static const ULONG64 Exp_value_1 = Exp_value_offset + 1;    static const ULONG64 exp_value_2 = Exp_value_offset + 2; ... }; ... In this way, the code can do so if (p = = nullptr) throw exp_value_2; ... if (this_p = = 7) throw_exp_value_1; Wait a minute

2014-11-24~11-28 Work Memo

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.