memory.cpp
# // Filename: memory
#
# // Comment By: 凝霜
# // E-mail: mdl2009@vip.qq.com
# // Blog: http://blog.csdn.net/mdl13412
#
# // 智能指针在STL中只有一个auto_ptr, 用于对原生指针的生命周期进行管理,
# // 但是其本身有许多另其不安全的特性, 例如以一个auto_ptr去构造另一个
# // auto_ptr会导致对象所有权的转移, 另外如果两个只能指针同时指向一个
# // 原声指针就可能导致指针被意外的提前释放, 另一个auto_ptr对其解引用时,
# // 就会导致错误
# //
# // C++0x已经通过了::Boost::scoped_ptr的决案, 所以任何使用auto_ptr的
# // 情景都应该使用scoped_ptr替代, 因为其更安全, 但是仍然不能解决多个
# // 智能指针同时拥有一个对象导致的提前释放问题, 要解决这个问题, 请使用
# // ::Boost::shared_ptr
#
# // 我博客中还有一个我实现的auto_ptr, 大家可以参考
# // http://blog.csdn.net/mdl13412/article/details/6244631
#
# /*
# * Copyright (c) 1997
# * Silicon Graphics Computer Systems, Inc.
# *
# * Permission to use, copy, modify, distribute and sell this software
# * and its documentation for any purpose is hereby granted without fee,
# * provided that the above copyright notice appear in all copies and
# * that both that copyright notice and this permission notice appear
# * in supporting documentation. Silicon Graphics makes no
# * representations about the suitability of this software for any
# * purpose. It is provided "as is" without express or implied warranty.
# *
# */
#
# #ifndef __SGI_STL_MEMORY
# #define __SGI_STL_MEMORY
#
# #include <stl_algobase.h>
# #include <stl_alloc.h>
# #include <stl_construct.h>
# #include <stl_tempbuf.h>
# #include <stl_uninitialized.h>
# #include <stl_raw_storage_iter.h>
#
# // Note: auto_ptr is commented out in this release because the details
# // of the interface are still being discussed by the C++ standardization
# // committee. It will be included once the iterface is finalized.
#
# #if 0
# #if defined(_MUTABLE_IS_KEYWORD) && defined(_EXPLICIT_IS_KEYWORD) && \
# defined(__STL_MEMBER_TEMPLATES)
#
# __STL_BEGIN_NAMESPACE
#
# template <class X> class auto_ptr
# {
# private:
# X* ptr; // 托管的原生指针
# mutable bool owns; // 是否拥有托管指针
# public:
# typedef X element_type;
#
# // 显式构造函数, 防止隐式转换
# // 通常接收一个原生指针进行构造
# // 构造函数不能失败, 故不能抛出异常
# explicit auto_ptr(X* p = ) __STL_NOTHROW : ptr(p), owns(p) {}
#
# // auto_ptr 可以以相同类型的 auto_ptr 进行构造
# // 注意: 对象所有权发生转移, 用于构造的只能指针释放对象所有权
# auto_ptr(const auto_ptr& a) __STL_NOTHROW : ptr(a.ptr), owns(a.owns) {
# a.owns = ;
# }
#
# // auto_ptr 可以以另一种相关类型的 auto_ptr 进行构造
# // 注意: T 必须能转换成 X 类型, 对象所有权发生转移
# template <class T> auto_ptr(const auto_ptr<T>& a) __STL_NOTHROW
# : ptr(a.ptr), owns(a.owns) {
# a.owns = ;
# }
#
# // 重载operator =, 首先判断是否是本身, 如果不是则进行对象所有权的转移
# auto_ptr& operator=(const auto_ptr& a) __STL_NOTHROW {
# if (&a != this) {
# if (owns)
# delete ptr;
# owns = a.owns;
# ptr = a.ptr;
# a.owns = ;
# }
# // 个人感觉应该在此加上
# // return *this;
# }
#
# // 和上面的operator =功能一样, 但是提供了兼容类型的转换操作
# template <class T> auto_ptr& operator=(const auto_ptr<T>& a) __STL_NOTHROW {
# if (&a != this) {
# if (owns)
# delete ptr;
# owns = a.owns;
# ptr = a.ptr;
# a.owns = ;
# }
#
# // 个人感觉应该在此加上
# // return *this;
# }
#
# // auto_ptr生命周期结束, 释放对象所有权, 实现资源释放目的
# ~auto_ptr() {
# if (owns)
# delete ptr;
# }
#
# // 提供和原生指针一样的操作
# X& operator*() const __STL_NOTHROW { return *ptr; }
# X* operator->() const __STL_NOTHROW { return ptr; }
#
# // 获取原生指针的地址, 主要用于一些只接受原生指针的函数
# X* get() const __STL_NOTHROW { return ptr; }
# // 释放指针所有权, 并返回原生指针
# // 主要用于取消指针托管
# X* release const __STL_NOTHROW { owns = false; return ptr }
# };
#
# __STL_END_NAMESPACE
# #endif /* mutable && explicit && member templates */
# #endif /* 0 */
#
#
# #endif /* __SGI_STL_MEMORY */
#
#
# // Local Variables:
# // mode:C++
# // End:

STL memory.cpp的更多相关文章

  1. STL之Errors and Exceptions

    Error Handling STL设计的目标是性能最优化,而不是最安全. 错误检查是极其浪费时间的,因此,STL对于错误处理几乎没有做处理,因此,这对STL的使用者的要求就非常高. 为什么不采取错误 ...

  2. STL之set && multiset

    一.set 在了解关联容器set之前,让我们先来看看下面这个例子,并猜测该例子输出什么: // stl/set1.cpp #include <iostream> #include < ...

  3. C++ STL源码剖析

    stl_config.h defalloc.h stl_alloc.h memory.cpp stl_construct.h stl_uninitialized.h stl_iterator.h ty ...

  4. 在android app中使用STL库(转)

    1.在jni目录下新建Application.mk; 加入 APP_STL := stlport_static右边的值还可以换成下面几个: system - 使用默认最小的C++运行库,这样生成的应用 ...

  5. NDK编译STL

    方法: 1.在jni目录下新建Application.mk; 加入 APP_STL :=  stlport_static  右边的值还可以换成下面几个: system - 使用默认最小的C++运行库, ...

  6. 怎么样android app正在使用STL库

    方法: 1.在jni文件夹下新建Application.mk; 增加 APP_STL := stlport_static右边的值还能够换成以下几个: system - 使用默认最小的C++执行库,这样 ...

  7. C/C++代码静态分析工具调研

    C/C++代码静态分析工具调研 摘自:https://www.jianshu.com/p/92886d979401 简述 静态分析(static analysis)是指在不执行代码的情况下对其进行分析 ...

  8. 通过OCCI连接oracle(C++)

    OCCI介绍 OCCI:Oracle C++调用接口(OCCI),即Oracle的C++API,允许你使用面向对象的特性.本地类.C++语言的方法来访问Oracle数据库. OCCI优势 基于标准C+ ...

  9. RTABMAP-ROS RGB-D的建图原理

    CoreNode.cpp: new CoreWrapper -- CoreWrapper.cpp: process() -- mapsManager_.updateMapCaches MapsMana ...

随机推荐

  1. Coursera machine learning 第二周 编程作业 Linear Regression

    必做: [*] warmUpExercise.m - Simple example function in Octave/MATLAB[*] plotData.m - Function to disp ...

  2. python tensorflow 学习

    Tensorflow系列——Saver的用法:http://blog.csdn.net/u011500062/article/details/51728830 Tensorflow学习系列(二): t ...

  3. byte[] 、Bitmap与Drawbale 三者直接的转换

    经常遇到这种类似头疼的问题 byte[] .Bitmap与Drawbale 三者直接的转换 1.byte[] ->Bitmap Bitmap Bitmap = BitmapFactory.dec ...

  4. SQL SERVER 查看表是否存在

    查看表是否存在 if exists(select 1 from sysobjects where id = OBJECT_ID('数据库名称.dbo.表明称')) drop table 为字段添加注释 ...

  5. docker笔记一

    docker概念介绍: docker 是一个装在linux上的普通的软件.利用docker的命令,可以创建一个带有linux操作系统的镜像文件,docker命令运行这个带的linux操作系的镜像文件, ...

  6. PLSQL使用技巧----加快你的编程效率

    使用PLSQL 编程效率明显有所提高了 1.登录后默认自动选中My Objects      默认情况下,PLSQL Developer登录后,Brower里会选择All objects,如果你登录的 ...

  7. nginx + uWSGI 为 django 提供高并发

    django 的并发能力真的是令人担忧,这里就使用 nginx + uwsgi 提供高并发 nginx 的并发能力超高,单台并发能力过万(这个也不是绝对),在纯静态的 web 服务中更是突出其优越的地 ...

  8. java堆分析神器MAT

    Memory Analyzer(MAT) 基于Eclipse的软件 http://www.eclipse.org/mat/

  9. hibernate Session的CRUD操作

    使用Session里面的方法进行CRUD操作 (1) 增加 save 方法 (2) 查找 get 方法(根据id查) (3) 修改 update 方法 (4) 删除 delete 方法 1.增加 /* ...

  10. python-2 什么是函数

    函数是什么? 定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 减少重复代码 使程序变的可扩展 使程序变得易维护 形参变量只有在被调用时才 ...