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.