STL memory.cpp
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的更多相关文章
- STL之Errors and Exceptions
Error Handling STL设计的目标是性能最优化,而不是最安全. 错误检查是极其浪费时间的,因此,STL对于错误处理几乎没有做处理,因此,这对STL的使用者的要求就非常高. 为什么不采取错误 ...
- STL之set && multiset
一.set 在了解关联容器set之前,让我们先来看看下面这个例子,并猜测该例子输出什么: // stl/set1.cpp #include <iostream> #include < ...
- C++ STL源码剖析
stl_config.h defalloc.h stl_alloc.h memory.cpp stl_construct.h stl_uninitialized.h stl_iterator.h ty ...
- 在android app中使用STL库(转)
1.在jni目录下新建Application.mk; 加入 APP_STL := stlport_static右边的值还可以换成下面几个: system - 使用默认最小的C++运行库,这样生成的应用 ...
- NDK编译STL
方法: 1.在jni目录下新建Application.mk; 加入 APP_STL := stlport_static 右边的值还可以换成下面几个: system - 使用默认最小的C++运行库, ...
- 怎么样android app正在使用STL库
方法: 1.在jni文件夹下新建Application.mk; 增加 APP_STL := stlport_static右边的值还能够换成以下几个: system - 使用默认最小的C++执行库,这样 ...
- C/C++代码静态分析工具调研
C/C++代码静态分析工具调研 摘自:https://www.jianshu.com/p/92886d979401 简述 静态分析(static analysis)是指在不执行代码的情况下对其进行分析 ...
- 通过OCCI连接oracle(C++)
OCCI介绍 OCCI:Oracle C++调用接口(OCCI),即Oracle的C++API,允许你使用面向对象的特性.本地类.C++语言的方法来访问Oracle数据库. OCCI优势 基于标准C+ ...
- RTABMAP-ROS RGB-D的建图原理
CoreNode.cpp: new CoreWrapper -- CoreWrapper.cpp: process() -- mapsManager_.updateMapCaches MapsMana ...
随机推荐
- mysql ODBC连接配置
1.软件包安装 [root@server1 mysql]# rpm -ivh MySQL-server-5.1.72-1.glibc23.i386.rpm [root@server1 mysql]# ...
- 要胀爆的Angular1.0
尝试从http请求上遏制缓存: http://blog.csdn.net/u010039979/article/details/54376856 if (!$httpProvider.defaults ...
- Oracle11g完全卸载方法
一.在oracle11G以前卸载oracle会存在卸载不干净,导致再次安装失败的情况,在运行services.msc打开服务,停止Oracle的所有服务. 二. oracle11G自带一个卸载批处理\ ...
- 2218 补丁vs错误
2218 补丁vs错误 1999年CTSC国家队选拔赛 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 大师 Master 题解 题目描述 Description 错 ...
- python多进程-----multiprocessing包
multiprocessing并非是python的一个模块,而是python中多进程管理的一个包,在学习的时候可以与threading这个模块作类比,正如我们在上一篇转载的文章中所提,python的多 ...
- javascript修改图片链接地址
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- Angular关于$anchorScroll的定位滚动
以下是实现定位滚动的代码: <!DOCTYPE html> <html lang="en" ng-app="app"> <head ...
- jqcloud 标签云效果
官网地址: http://mistic100.github.io/jQCloud/index.htmlgithub 地址: https://github.com/lucaong/jQCloud使用 & ...
- Js中的apply和call
1.call和apply都是为了改变某个函数运行时的上下文而存在的 2.也就是改变函数体内this的指向. 3.二者的作用完全一样,只是接受参数的方式不太一样. 4.call 需要把参数按顺序传递进去 ...
- python 安装anaconda, numpy, pandas, matplotlib 等
如果没安装anaconda,则这样安装这些库: pip install numpy pip install pandas pip install matplotlib sudo apt-get ins ...