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. 将PHP 5.3.3 (cli)升级到PHP 5.6.31 (cli)

    centos默认系统安装的是php5.3 [root@sz-local1 scripts]# rpm -qa |grep phpphp-pdo-5.3.3-47.el6.x86_64php-mysql ...

  2. kafka的并行度与JStorm性能优化

    kafka的并行度与JStorm性能优化 > Consumers Messaging traditionally has two models: queuing and publish-subs ...

  3. SQL SERVER 查看表是否存在

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

  4. 开关openCV

    #include <cv.h> #include <highgui.h> #include <stdio.h> //开关 ; void switch_callbac ...

  5. matlab常用的一些程序和功能

    ~ 去除误匹配算法(matlab) 1.ransac算法 [tform,matchedPoints1,matchedPoints2] = ...    estimateGeometricTransfo ...

  6. Elatsicsearch分片和副本相关知识

    1.分片和副本 1.1什么是分片 简单来讲就是咱们在ES中所有数据的文件块,也是数据的最小单元块,整个ES集群的核心就是对所有分片的分布.索引.负载.路由等达到惊人的速度. 分片是把索引数据切分成多个 ...

  7. python调用java jython

    环境:openjdk8,python2.7,jython2.7jython下载地址     http://www.jython.org/downloads.html 下载完成后,运行下面命令 java ...

  8. GetTickCount的几个案例

    一,获得运行时间: var T1,T2 : double; begin T1 := GetTickCount; //需要做的事情 T2 := GetTickCount; ShowMessage( fl ...

  9. 斐波那契数列F(n)【n超大时的(矩阵加速运算) 模板】

    hihocoder #1143 : 骨牌覆盖问题·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 骨牌,一种古老的玩具.今天我们要研究的是骨牌的覆盖问题: 我们有一个 ...

  10. Logstash添加Protobuf解析插件

    logstash收集日志时,日志部分是由google的protobuf工具打印的,直接利用json解析会造成部分无法解析的问题 搜索后发现有个logstash的protobuf插件 在logstash ...