草庐IT

mem_alloc

全部标签

c++ - Clang:将 bind 或 mem_fn 与 string::c_str 和 transform 结合使用时出现问题

尝试将std::stringvector转换为constchar*vector:#include#include#include#includeintmain(intargc,char**argv){std::vectorvalues;values.push_back("test1");values.push_back("test2");values.push_back("test3");std::vectorc_values(values.size());std::transform(values.begin(),values.end(),c_values.begin(),std::

c++ - 带有 ref_qualified 成员函数的 std::mem_fn

有什么方法可以通过std::mem_fn使用ref限定的成员函数?下面的代码编译失败:classDeadPool{public:voidjump()&{std::cout错误信息:mem_fn_ex.cc:18:15:error:nomatchingfunctionforcallto'mem_fn'autocobj=std::mem_fn(&DeadPool::jump);//Won'tcompile^~~~~~~~~~~/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/functional:1233:1:not

c++ - 为什么我会收到 CL_MEM_OBJECT_ALLOCATION_FAILURE?

我在GPU上分配一个cl_mem缓冲区并对其进行处理,在超过一定尺寸之前效果很好。在那种情况下,分配本身会成功,但执行或复制不会。我确实想使用设备的内存来加快操作速度,所以我分配如下:buf=clCreateBuffer(cxGPUContext,CL_MEM_WRITE_ONLY,buf_size,NULL,&ciErrNum);现在我不明白的是大小限制。我正在复制大约16MB,但应该可以使用大约128MB(参见CL_DEVICE_MAX_MEM_ALLOC_SIZE)。为什么这些数字相差如此之大?这是oclDeviceQuery的一些摘录:CL_PLATFORM_NAME:NVID

c++ - 函数不会抛出 bad_alloc 异常

我正在尝试从Stroustrup的C++PL4书中做一个练习。任务是:Allocatesomuchmemoryusingnewthatbad_allocisthrown.Reporthowmuchmemorywasallocatedandhowmuchtimeittook.Dothistwice:oncenotwritingtotheallocatedmemoryandoncewritingtoeachelement.以下代码不会抛出std::bad_alloc异常。执行程序后,我在终端中收到消息“Killed”。还有。以下代码在~4秒后退出。但是当我取消注释内存使用消息时//++i;

C++ std::bad_alloc 错误

我正在开发C++程序(C++98)。它读取一个包含很多行(10000行)的文本文件。这些是制表符分隔值,然后我将其解析为Vector对象的Vector。然而,它似乎适用于某些文件(较小),但我的一个文件给我以下错误(该文件有10000行,大小为90MB)。我猜这是一个内存相关的问题?你能帮帮我吗?错误terminatecalledafterthrowinganinstanceof'std::bad_alloc'what():std::bad_allocAbort代码voidAppManager::go(stringcustomerFile){vector>vals=fileReader

c++ - std::tr1::mem_fn 返回类型

我想把这个结果:std::tr1::mem_fn(&ClassA::method);在一个变量中,这个变量的类型是什么?看起来像这样:MagicalTypefun=std::tr1::mem_fn(&ClassA::method);此外,std::tr1::bind的结果类型是什么?谢谢! 最佳答案 未指定std::tr1::mem_fn和std::tr1::bind的返回类型。您可以将std::tr1::bind的结果存储在std::tr1::function中:structClassA{voidFunc(){}};ClassAo

c++ - 为什么我得到 "cannot allocate an array of constant size 0"?

这个问题在这里已经有了答案:WhathappensifIdefinea0-sizearrayinC/C++?(8个答案)关闭8年前。我正在为学校做一个扫雷程序,但我的代码中一直出现这个错误cannotallocateanarrayofconstantsize0我不知道为什么会这样;我没有分配大小——我将它设置为0。另一个问题是,我如何通过char读取我的输入char,这样我就可以将它保存在我的数组?正如您在下面看到的,我正在使用输入和输出。我评论了我的输入和输出,这样你们就可以看到我在这个程序中使用了什么。我想通过char读取char,这样我就可以将所有map保存在数组中。我正在使用M

c++ - 为什么 std::allocator<>::deallocate() 有一个未使用的 size_type 参数?

使用std::allocator时,deallocate函数需要pointer参数,和一个size_type参数(std::allocator::deallocate(std::allocator::pointerp,std::allocator::size_type)。但是,没有使用size_type,也不是可选的。那么为什么它在那里?这让我很困惑,因为它应该是可选的,甚至不在那里,因为它没有在函数中使用.编辑:MSVC的分配器实现deallocatevoiddeallocate(pointer_Ptr,size_type){//deallocateobjectat_Ptr,igno

c++ - 反向迭代器错误 : no match for 'operator!=' in 'rcit != std::vector<_Tp, _Alloc>::rend() with _Tp = int, _Alloc = std::allocator'

代码A:vector::const_reverse_iteratorrcit;vector::const_reverse_iteratortit=v.rend();for(rcit=v.rbegin();rcit!=tit;++rcit)cout代码B:vector::const_reverse_iteratorrcit;for(rcit=v.rbegin();rcit!=v.rend();++rcit)coutCODEA工作正常但是为什么代码B通过错误:DEVC++\vector_test.cpp在'rcit!=std::vector::rend()与_Tp=int,_Alloc=s

c++ - 为什么 eglMakeCurrent 因 EGL_BAD_ALLOC 而失败?

我正在使用OpenGLES2.0和AndroidNDKr8b。我有一个用于工作线程的共享上下文。当我尝试使用eglMakeCurrent将共享上下文绑定(bind)到工作线程时,我收到错误EGL_BAD_ALLOC。现在让我感到困惑的是这段代码之前工作得很好......我不确定我做了什么来破坏它......EGL文档说这个错误与资源不可用有关,但我正在运行曾经在这个完全相同的设备上完美运行的同一个应用程序,并且所有纹理都可以从主线程正常加载。那么可能导致此错误的原因是什么?这是我的egl初始化:boolInitialize(void*displaySurface){assert(dis