jjzjj

allocator

全部标签

c++ - move 哪个 throw ?

据我了解,move构造函数和move赋值必须标记为noexcept,以便编译器在例如在vector内部重新分配时使用它们。但是,是否存在move分配、move构造可能实际抛出的真实案例?更新:例如,在构造时具有分配资源的类不能是不可抛出的。 最佳答案 However,isthereanyreal-worldcasewhereamove-assign,move-construct(orswap)mightactuallythrow?是的。考虑std::list的实现.end迭代器必须指向列表中的“最后一个元素”。存在std::list

c++ - vector 的数据如何对齐?

如果我想用SSE处理std::vector中的数据,我需要16字节对齐。我怎样才能做到这一点?我需要编写自己的分配器吗?或者默认分配器是否已经与16字节边界对齐? 最佳答案 C++标准需要分配函数(malloc()和operatornew())来分配适合任何标准类型的内存。由于这些函数不接收对齐要求作为参数,实际上这意味着所有分配的对齐方式都是相同的,并且是具有最大对齐要求的标准类型,通常是longdouble和/或longlong(参见boostmax_alignunion)。vector指令,例如SSE和AVX,比标准C++分配

c++ - bad_alloc 在类 Texture 上调用 new 时

这是有问题的行:Texture*texture=newTexture(...);我在这里收到来自bad_alloc的信息:void*__CRTDECLoperatornew(size_tsize)_THROW1(_STDbad_alloc){//trytoallocatesizebytesvoid*p;while((p=malloc(size))==0)if(_callnewh(size)==0){//reportnomemorystaticconststd::bad_allocnomem;_RAISE(nomem);}return(p);}大小是~28字节大到目前为止,该程序已在32

c++ - Boost 快速池分配器有函数指针问题?

这是Boost错误还是我做错了什么?#include#includeintmain(){typedefconststd::stringkey;typedefdouble*(*value)(constint&);std::map>map_with_standard_allocator;//worksstd::map,boost::fast_pool_allocator>>map_with_boost_allocator;//fails}最后一行无法在带有Boost1.40和1.48的MSVisualStudio2008下编译。不过,它在g++4.5.3(Cygwin)下编译得很好。错误是

c++ - 使用 stxxl 队列时为 `pointer being freed was not allocated`

我的代码似乎可以工作(由于上述错误,我还没有在大型数据集上尝试过)。代码:#include#include#includeintmain(){//queueq;//thisworksstxxl::queueq;//doesnotworkfor(inti=0;i我的简单.stxxl就是:disk=./testfile,0,syscall但我的错误是:stackexchangeexample(3884)malloc:***errorforobject0x101c04000:pointerbeingfreedwasnotallocated***setabreakpointinmalloc_e

《Cache-Aided MEC for IoT: Resource Allocation Using Deep Graph Reinforcement Learning》阅读笔记

《Cache-AidedMECforIoT:ResourceAllocationUsingDeepGraphReinforcementLearning》阅读笔记QuestionContributionRelatedworksSystemmodelnetworkarchitecturecommunicationmodelcomputingmodelcachingmodelProblemformulationOptimizationObjectiveproblemformulationDGRL-BasedResourceAllocationAlgorithmSimulationresultsCon

c++ - 无法在 MinGW 中捕获 bad_alloc

我正在为家庭作业编写一个程序,我需要分配许多对象来检查位置和性能等方面的事情。我似乎无法捕捉到new抛出的异常#include"List.h"#include#includeintmain(intargc,char**argv){coutnext=ptrList2;ptrList2->previous=ptrList;ptrList=ptrList2;}}catch(bad_allocconst&e){cout结果:ThisapplicationhasrequestedtheRuntimetoterminateitinanunusualway.Pleasecontacttheappli

c++ - `std::vector` 在调整大小时抛出 "bad allocation"异常

我在C++dll中有以下代码,我通过JNI调用它:std::vectormyVector;myVector.resize(10000000,0);我收到“错误分配”异常,即使vector的最大大小应该大于10000000。我应该使用什么工具来跟踪内存分配,以便定位任何内存泄漏?如果真的没有内存泄漏,我该如何减少vector的占用空间以确保我有足够的空间? 最佳答案 我知道这可能是找出分配大小的最差解决方案。所以这里是:主要.cpp:#include"jni.h"#include#include#if(_MSC_VER==1800)|

c++ - 在不复制的情况下构造一个范围内的 vector

我有一个类包装了大量字节,这些字节是网络数据包。该类实现了一个队列并提供(除其他外)front()函数,该函数返回构成队列中最旧数据包的字节常量vector。classBuffer{unsignedchardata[65536];unsignedintoffset;unsignedintlength;[...]//otherfieldsformaintainingwriteptretc.public:conststd::vectorfront(){returnstd::vector(data+offset,data+offset+length);}//othermethodsforac

c++ - 琐碎的分配器感知容器?

我正在研究/玩分配器,试图了解它是如何工作的。但是我在尝试实现接受分配器的普通容器时遇到了问题。现在我结束了这个:template>classContainer{public:usingallocator_type=Allocator;usingvalue_type=T;usingpointer=typenamestd::allocator_traits::pointer;usingreference=value_type&;usingsize_type=std::size_t;Container(size_typen=0,constallocator_type&allocator=a