xmemory std::allocator源代码及注释

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

 

//D:/Program Files/Microsoft Visual Studio 8/VC/include/xmemory

// xmemory internal header (from )
#pragma once
#ifndef _XMEMORY_
#define _XMEMORY_
#ifndef RC_INVOKED
#include
#include
#include
#include

#ifdef _MSC_VER
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,3)

#pragma warning(disable: 4100)
#endif /* _MSC_VER */

#ifndef _FARQ /* specify standard memory model */
#define _FARQ
#define _PDFT ptrdiff_t
#define _SIZT size_t
#endif /* _FARQ */

#define _CPOINTER_X(T, A) /
typename A::template rebind::other::const_pointer
#define _CREFERENCE_X(T, A) /
typename A::template rebind::other::const_reference
#define _POINTER_X(T, A) /
typename A::template rebind::other::pointer
#define _REFERENCE_X(T, A) /
typename A::template rebind::other::reference

_STD_BEGIN
// TEMPLATE FUNCTION _Allocate
template inline
_Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *)
{ // check for integer overflow
if (_Count <= 0)
_Count = 0;
else if (((_SIZT)(-1) / _Count) < sizeof (_Ty))
_THROW_NCEE(std::bad_alloc, NULL);

// allocate storage for _Count elements of type _Ty
return ((_Ty _FARQ *)::operator new(_Count * sizeof (_Ty)));
}

// TEMPLATE FUNCTION _Construct
templateclass _T2> inline
void _Construct(_T1 _FARQ *_Ptr, const _T2& _Val)
{ // construct object at _Ptr with value _Val
void _FARQ *_Vptr = _Ptr;
::new (_Vptr) _T1(_Val);// [::] new [placement] new-type-name [new-initializer]
}

// TEMPLATE FUNCTION _Destroy
template inline
void _Destroy(_Ty _FARQ *_Ptr)
{ // destroy object at _Ptr
_DESTRUCTOR(_Ty, _Ptr);
}

//特化??

template<> inline
void _Destroy(char _FARQ *)
{ // destroy a char (do nothing)
}

template<> inline
void _Destroy(wchar_t _FARQ *)
{ // destroy a wchar_t (do nothing)
}

// TEMPLATE CLASS _Allocator_base
template
struct _Allocator_base
{ // base class for generic allocators
typedef _Ty value_type;
};

// TEMPLATE CLASS _Allocator_base
template
struct _Allocator_base
{ // base class for generic allocators for const _Ty
typedef _Ty value_type;
};

// TEMPLATE CLASS allocator
template
class allocator
: public _Allocator_base<_Ty>
{ // generic allocator for objects of class _Ty
public:
typedef _Allocator_base<_Ty> _Mybase;
typedef typename _Mybase::value_type value_type;
typedef value_type _FARQ *pointer;
typedef value_type _FARQ& reference;
typedef const value_type _FARQ *const_pointer;
typedef const value_type _FARQ& const_reference;

typedef _SIZT size_type;
typedef _PDFT difference_type;

template
struct rebind
{ // convert an allocator<_Ty> to an allocator <_Other>
typedef allocator<_Other> other;
};

pointer address(reference _Val) const
{ // return address of mutable _Val
return (&_Val);
}

const_pointer address(const_reference _Val) const
{ // return address of nonmutable _Val
return (&_Val);
}

allocator() _THROW0()
{ // construct default allocator (do nothing)
}

allocator(const allocator<_Ty>&) _THROW0()
{ // construct by copying (do nothing)
}

template
allocator(const allocator<_Other>&) _THROW0()
{ // construct from a related allocator (do nothing)
}

template
allocator<_Ty>& operator=(const allocator<_Other>&)
{ // assign from a related allocator (do nothing)
return (*this);
}

void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
::operator delete(_Ptr);
}

pointer allocate(size_type _Count)
{ // allocate array of _Count elements
return (_Allocate(_Count, (pointer)0));
}

pointer allocate(size_type _Count, const void _FARQ *)
{ // allocate array of _Count elements, ignore hint
return (allocate(_Count));
}

void construct(pointer _Ptr, const _Ty& _Val)
{ // construct object at _Ptr with value _Val
_Construct(_Ptr, _Val);
}

void destroy(pointer _Ptr)
{ // destroy object at _Ptr
_Destroy(_Ptr);
}

_SIZT max_size() const _THROW0()
{ // estimate maximum array size
_SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
return (0 < _Count ? _Count : 1);
}
};

// allocator TEMPLATE OPERATORS
templateclass _Other> inline
bool operator==(const allocator<_Ty>&, const allocator<_Other>&) _THROW0()
{ // test for allocator equality (always true)
return (true);
}

templateclass _Other> inline
bool operator!=(const allocator<_Ty>&, const allocator<_Other>&) _THROW0()
{ // test for allocator inequality (always false)
return (false);
}

// CLASS allocator
template<> class _CRTIMP2_PURE allocator
{ // generic allocator for type void
public:
typedef void _Ty;
typedef _Ty _FARQ *pointer;
typedef const _Ty _FARQ *const_pointer;
typedef _Ty value_type;

template
struct rebind
{ // convert an allocator to an allocator <_Other>
typedef allocator<_Other> other;
};

allocator() _THROW0()
{ // construct default allocator (do nothing)
}

allocator(const allocator<_Ty>&) _THROW0()
{ // construct by copying (do nothing)
}

template
allocator(const allocator<_Other>&) _THROW0()
{ // construct from related allocator (do nothing)
}

template
allocator<_Ty>& operator=(const allocator<_Other>&)
{ // assign from a related allocator (do nothing)
return (*this);
}
};

// TEMPLATE FUNCTION _Destroy_range
templateclass _Alloc> inline
void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)
{ // destroy [_First, _Last)
_Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
}

templateclass _Alloc> inline
void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
_Nonscalar_ptr_iterator_tag)
{ // destroy [_First, _Last), arbitrary type
for (; _First != _Last; ++_First)
_Al.destroy(_First);
}

templateclass _Alloc> inline
void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
_Scalar_ptr_iterator_tag)
{ // destroy [_First, _Last), scalar type (do nothing)
}
_STD_END

#ifdef _MSC_VER
#pragma warning(default: 4100)

#pragma warning(pop)
#pragma pack(pop)
#endif /* _MSC_VER */

#endif /* RC_INVOKED */
#endif /* _XMEMORY_ */

/*
* Copyright (c) 1992-2005 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/

/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* 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.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
V4.05:0009 */

微软STL开源项目深度解析:从源码学习到实战应用 标准模板库(STL)是C++编程的核心基础,它提供了一套通用的容器、算法和迭代器组件,通过模板技术实现类型安全的泛型编程。其设计原理基于数据结构和算法的抽象,旨在提升代码复用性和运行效率。掌握STL源码对于深入理解C++语言特性、内存管理和性能优化至关重要,尤其在系统级开发和性能敏感场景中价值显著。在实际工程中,开发者常需调试容器行为、分析算法复杂度或定制分配器,此时直接查阅工业级实现源码成为高效手段。微软将MSVC STL作为独立项目开源,为学习者提供了权威的参考实现,让开发者能直观探究`std::vec 阅读详情

相关推荐

智智指针源码分析之xmemory 文件里的类 allocator

顾名思义,这个类涉及了内存分配与释放方面。由类 _Default_allocator_traits 会对其调用。详情见上传代码文件。

zhangzhangkeji的博客 180

xmemory Line: 141报错,在std::vector容器里装Vector2d等Eigen类型的数据时出错的根本性解决方案

继我昨天发的博客: 标题:报错VC\Tools\MSVC\14.27.29110\include\xmemory Line: 141 Expression: invalid argument解决方案 链接:xmemory报错 里面讲述了我遇到了vector内存问题及当时的解决方案,具体内容可以戳上述链接进入查看。 本来,我以为昨天的解决方案已经很好地解决了这个错误,结果,它(这个错误)就跟鬼火似的,一直跟随着我,所以它今天又找上门来了。这里再贴一下这个错误: 跟昨天一模一样。于是,我就根据昨天的代码优

zeeq的博客 3149

C语言头文件 XMEMORY

C语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XMEMORYC语言头文件 XME

c++ 在Xmemory中,引发了异常: 读取访问权限冲突。 _Pnext 是 0x708

C++ 在Xmemory中,引发了异常: 读取访问权限冲突

weixin_44370506的博客 6027

xmemory(348): error C4996: 'std::_Uninitialized_copy0': 的解决方法

我是在VS2012环境下,使用boost库中的函数时产生了如下的错误: xmemory(348): error C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe , 经过查资料和不断探索,找到了一个勉强的解决方法: 即,将_SCL_SECURE_NO_WARNINGS

chenkent888的专栏 5383

Solidity:变量数据存储和作用域 storage/memory/calldata

这样就能让合约的执行可以更加精确,不会因为技术上的误差而影响合约的结果。在不同存储类型相互赋值时候,有时会产生独立的副本(修改新变量不会影响原变量),有时会产生引用(修改新变量会影响原变量)。代替为小数点,来确保交易的精确度,并且防止精度的损失,利用以太单位可以避免误算的问题,方便程序员在合约中处理货币交易。局部变量是仅在函数执行过程中有效的变量,函数退出后,变量无效。),由于这类变量比较复杂,占用存储空间大,我们在使用时必须要声明数据存储的位置。状态变量是数据存储在链上的变量,所有合约内函数都可以访问,

目前专注区块链相关技术的学习与分享 2558

深入理解 STL allocator

由于std::set,std::multiset,std::map,std::multimap四种容器的插入删除操作性能高并且自动排序,在很多时候比如需要动态操作时往往会使用它们,然后由于容器内部使用的是节点,每次的插入或删除都要调用new或delete,往往容易造成碎片和性能下降,于是自定义的allocator出现了。这篇文章的目的就是详细讲解std::allocator的内部结构,为实现自

lifesider 1万+

memory std::allocator源代码注释.

<br />//D:/Program Files/Microsoft Visual Studio 8/VC/include/xmemory <br />// xmemory internal header (from )<br />#pragma once<br />#ifndef _XMEMORY_<br />#define _XMEMORY_<br />#ifndef RC_INVOKED<br />#include <br />#include <br />#include <br />#includ

na2650945的专栏 2207

allocator

allocator vs的 allocator 位置 #include <xmemory> vs 中的实现: 大概vs认为如果是内部封装的,都会在前面加下划线。所以,在xmemory头文件有个define #define _ALLOCATOR allocator 然后,当前文件的下面就有了 _ALLOCATOR的类模板. 这里有两个版本,一个是普通版本,一个是特化版本。 /* t...

u012989445的博客 339

关于STL allocator

关于STL 中allocator的接口与实现,C++标准有比较清楚的定义:allocator wiki 1. SGI STL版本的allocator并没有遵守C++标准。它只提供simple_alloc类共container使用,设计的allocator名字叫做alloc,有二级配置器。第一级配置采用malloc/free来实现allocate/deallocate,第二级配置器采用针对

zeroom的技术专栏 8338

C++第二部分——STL与泛型编程

目录认识header、版本、重要资源重要网页及书籍STL体系结构基础介绍容器之分类与各种测试Array的使用 认识header、版本、重要资源 标准库大于STL,STL分为六大部件,标准库80%都是STL。 namespace让你可以把你所需要的类,函数等包起来起一个名字让其不会与别人冲突。 如果单单只使用cout,可以用上图第二个std导入方法。 无论是何种C++编译器,他们对std的使用都是基本一样的 重要网页及书籍 CppReference.com gcc.gnu.org STL体系结构基础介

m0_47639800的博客 682

C++知识点总结5 内存管理

C/C++内存分布 【说明】 1.栈又叫堆栈,非静态局部变量/函数参数/返回值等等,栈是向下增长的。(栈可以通过函数_alloca进行动态分配,不过,所分配空间不能通过free或delete进行释放) 2.内存映射段是高效的I/O映射方式,用于装载一个共享的动态内存库。用户可使用系统接口创建共享内存,做进程间通信。(Linux课程如果没学到这块,现在只需要了解一下) 3.堆用于程序运行时动态内存分配(只能),堆是可以向上增长的。 4.数据段...

weixin_47641376的博客 362

[vs 2005]allocator

vs 2005中实现的各种容器其默认的内存分配模型是allocator,它声明在文件中。template class allocator : public _Allocator_base { // generic allocator for objects of class

huyinhou 675

深入理解C++中vector容器的原理,史上最详细的实现vector容器的教程,一文手把手带你实现自己的vector容器(包含迭代器的实现)

本文详细介绍了如何从零开始用c++自己手写一个std::vector容器,并对标准库中的vector的大部分功能做出了实现。通过阅读本篇文章,你可以对vector容器有更加深入的了解,并且通过自己实现一个vector也可以有效提升自己的c++编码水平。

greatming666的博客 3768
上一篇: VS2005配置QT4环境 (转) -- 以后装QT4有用
下一篇: C++免费库 (转) 看到好的BLOG文章,就记录下来
sunwenjun
博客等级 码龄21年 18粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值