Exercise tive C ++ item50: a reasonable time to replace New and delete

Source: Internet
Author: User

1. Operator new and operator Delete in the C ++ standard library can generally meet the requirements. However, for the following purposes, you can customize your own operator new and operator Delete versions:

  • Check application errors: for example, underrun (before the start point of the write point in the allocated block) and overrun (after the write point is at the end of the allocated block). You can customize operator new to overallocate memory, add a "signature" before and after the memory required by the customer to check whether the above error has occurred.
  • Collects statistics on the usage of dynamically allocated memory.
  • To increase the allocation and return speed: customizes a more efficient Memory Allocation Solution for specific scenarios.
  • To reduce the extra space overhead of the default Memory Manager.
  • To make up for the non-optimal homogeneous bits in the default distributor: Many architectures require that a specific type be placed on a specific memory address. For example, a pointer address must be a four or eight multiple, otherwise, hardware exceptions may occur during the runtime. If the dual-precision floating point number on the intel X86 system is 8-byte, the access speed will be much higher. By adjusting the memory allocation scheme to a full-bit version, the program efficiency can be greatly improved or even prevented from running errors.
  • To cluster related objects.
  • To obtain non-traditional behaviors: for example, if only C-compiled APIs are managed in the memory, a specific version should be defined for this purpose.

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.