C++ Gotchas 第6章 内存及资源管理

    技术2022-05-11  168

    6 . Memory and Resource Management

    6  内存及资源管理

     

    C++在内存管理方面提供了极大的弹性,但几乎没有多少C++程序员完全通透其理。C++在这一方面,经由重载(overloading)、名称隐藏(name hiding)、构造(constructors)与析构(destructors)、异常(exceptions)、静态函数(static functions)与虚函数(virtual functions)、运算符函数(operator functions)与非运算符函数(non-operator functions),一起为内存管理提供了非凡的弹性和可定制性。而不幸的是——或许也不可避免的是——事情变得有些复杂了。

     

    在本章中,我们来看一看C++的各种语言特征:如何一起用于内存管理;如何时而以令人吃惊的方式相互影响;如何消减其间的相互影响。

     

    内存只是程序所管理的许多资源之一,因此我们还要看一看,如何将其它资源绑定到内存,使我们可以利用C++纷繁的内存管理设施来管理其它资源。

     

     

    6  内存及资源管理

     

    Gotcha #60: Failure to Distinguish Scalar and Array AllocationGotcha条款60:没能区分单体内存分配与数组内存分配

     

    Gotcha #61: Checking for Allocation FailureGotcha条款61:检查内存分配失败的情形

     

    Gotcha #62: Replacing Global New and DeleteGotcha条款62:替换Global New和Global Delete

     

    Gotcha #63: Confusing Scope and Activation of Member new and deleteGotcha条款63:Member New和Member Delete之生存期与活动空间的迷惑

     

    Gotcha #64: Throwing String LiteralsGotcha条款64:抛出String Literals

     

    Gotcha #65: Improper Exception MechanicsGotcha条款65:不够适宜的异常机制

     

    Gotcha #66: Abusing Local AddressesGotcha条款66:滥用局部地址空间

     

    Gotcha #67: Failure to Employ Resource Acquisition Is InitializationGotcha条款67:没能秉持“Resource Acquisition Is Initialization(资源获取即初始化)”原则

     

    Gotcha #68: Improper Use of auto_ptrGotcha条款68:auto_ptr的不当用法

     


    最新回复(0)