STL defalloc.h
defalloc.h
. // Filename: defalloc.h
.
. // Comment By: 凝霜
. // E-mail: mdl2009@vip.qq.com
. // Blog: http://blog.csdn.net/mdl13412
.
. /*
8. *
9. * Copyright (c) 1994
10. * Hewlett-Packard Company
11. *
12. * Permission to use, copy, modify, distribute and sell this software
13. * and its documentation for any purpose is hereby granted without fee,
14. * provided that the above copyright notice appear in all copies and
15. * that both that copyright notice and this permission notice appear
16. * in supporting documentation. Hewlett-Packard Company makes no
17. * representations about the suitability of this software for any
18. * purpose. It is provided "as is" without express or implied warranty.
19. *
20. */
.
. // 这个文件提供原始的HP默认allocator, 仅仅是为了向后兼容
. //
. // 不要使用这个文件,除非你使用一个需要HP-style allocator的旧容器
. // SGI STL使用一个不同的allocator接口
. // SGI-style的allocator不针对对象类型进行参数化, 他使用void *指针
.
. #ifndef DEFALLOC_H
. #define DEFALLOC_H
.
. #include <new.h>
. #include <stddef.h>
. #include <stdlib.h>
. #include <limits.h>
. #include <iostream.h>
. #include <algobase.h>
.
. // 如果内存分配失败, 则直接退出程序
. template <class T>
. inline T* allocate(ptrdiff_t size, T*)
. {
. set_new_handler();
. T* tmp = (T*)(::operator new((size_t)(size * sizeof(T))));
. if (tmp == ) {
. cerr << "out of memory" << endl;
. exit();
. }
. return tmp;
. }
.
. template <class T>
. inline void deallocate(T* buffer)
. {
. ::operator delete(buffer);
. }
.
. // 标准的STL allocator接口
. template <class T>
. class allocator
. {
. public:
. // STL type_traits需要的标准定义
. typedef T value_type;
. typedef T* pointer;
. typedef const T* const_pointer;
. typedef T& reference;
. typedef const T& const_reference;
. typedef size_t size_type;
. typedef ptrdiff_t difference_type;
.
.
. pointer allocate(size_type n)
. {
. return ::allocate((difference_type)n, (pointer));
. }
. void deallocate(pointer p) { ::deallocate(p); }
. pointer address(reference x) { return (pointer)&x; }
. const_pointer const_address(const_reference x)
. {
. return (const_pointer)&x;
. }
. //
. size_type init_page_size()
. {
. return max(size_type(), size_type(/sizeof(T)));
. }
. size_type max_size() const
. {
. return max(size_type(), size_type(UINT_MAX/sizeof(T)));
. }
. };
.
. // 仅使用void *类型的指针
. class allocator<void>
. {
. public:
. typedef void* pointer;
. };
.
. #endif
STL defalloc.h的更多相关文章
- STL stl_config.h
stl_config.h . // Filename: stl_config.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // ...
- STL stl_alloc.h
# // Comment By: 凝霜 # // E-mail: mdl2009@vip.qq.com # // Blog: http://blog.csdn.net/mdl13412 # # // ...
- STL stl_uninitialized.h
stl_uninitialized.h // Filename: stl_uninitialized.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com ...
- STL stl_construct.h
stl_construct.h // Filename: stl_construct.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog ...
- STL六大组件之——分配器(内存分配,好深奥的东西)
SGI设计了双层级配置器,第一级配置器直接使用malloc()和free(),第二级配置器则视情况采用不同的策略:当配置区块超过128bytes时,视之为“足够大”,便调用第一级配置器:当配置区小于1 ...
- 【转】STL空间配置器
STL空间配置器(allocator)在所有容器内部默默工作,负责空间的配置和回收.STL标准为空间配置器定义了标准接口(可见<STL源码剖析>P43).而具体实现细节则由各编译器实现版本 ...
- STL内存管理
1. 概述 STL Allocator是STL的内存管理器,也是最低调的部分之一,你可能使用了3年stl,但却不知其为何物. STL标准如下介绍Allocator the STL includes s ...
- 侯捷STL课程及源码剖析学习2: allocator
以STL 的运用角度而言,空间配置器是最不需要介绍的东西,它总是隐藏在一切组件(更具体地说是指容器,container)的背后,默默工作默默付出. 一.分配器测试 测试代码 #include < ...
- SGI STL内存配置器存在内存泄漏吗?
阅读了SGI的源码后对STL很是膜拜,很高质量的源码,从中学到了很多.温故而知新!下文中所有STL如无特殊说明均指SGI版本实现. STL 内存配置器 STL对内存管理最核心部分我觉得是其将C++对象 ...
随机推荐
- phalcon builder get raw sql
$this->modelsManager->createBuilder()->from('table')->where('a = "a"')->lim ...
- html5小趣味知识点系列(一)spellcheck
发现一些h5的系ode知识点增加一些趣味性 实用性 不敢妄自评论 觉得有用就用一下 没用就路过一下 spellcheck属性 它的功能是针对用户输入的文本内容进行拼写和语法检查 用于input 和 ...
- textarea中的内容的获取
今天他们说为啥获取不到textarea的数值 这个问题让我很纳闷 为什么会获取不到呢? 按照逻辑来说 同样都是表单元素 怎么可能出现呢? 我就看了一眼代码 alert($("#texta ...
- ios错误ignoring file xxx missing required architecture x86_64 in file
错误ignoring file xxx missing required architecture x86_64 in file 解决方法: 1.在Project target里“Architectu ...
- python 基础 9.7 创建表
一. 创建表 #/usr/bin/python #-*- coding:utf-8 -*- #@Time :2017/11/22 18:05 #@Auther :liuzhenchuan #@Fi ...
- Qt状态机框架(状态机就开始异步的运行了,也就是说,它成为了我们应用程序事件循环的一部分了)
状态机框架 Qt中的状态机框架为我们提供了很多的API和类,使我们能更容易的在自己的应用程序中集成状态动画.这个框架是和Qt的元对象系统机密结合在一起的.比如,各个状态之间的转换是通过信号触发的,状态 ...
- Module 'curl' already loaded in Unknown on line 0
Module 'curl' already loaded in Unknown on line 0 应该是php binary已经包含curl,你又动态加载了一遍.屏蔽掉你的extension 引用, ...
- GitHub提示 Error: Key already in use解决办法
GitHub提示 Error: Key already in use解决办法GitHub提示 Error: Key already in use解决办法2014年09月05日 ⁄ 综合 ⁄ 共 290 ...
- rails数据验证
@user1 = :name => "zhou" 与 @user2 = :name=> "ZHOU" 在为保存之前都有可能通过第一关validate ...
- 基于事件驱动的前端通信框架(封装socket.io)
socket.io的使用可以很轻松的实现websockets,兼容所有浏览器,提供实时的用户体验,并且为程序员提供客户端与服务端一致的编程体验.但是在使用socket.io的过程中,由于业务需求需要同 ...