草庐IT

allocating

全部标签

c++ - 为什么 `std::pmr::polymorphic_allocator` 不会在容器移动时传播?

来自http://en.cppreference.com/w/cpp/memory/polymorphic_allocator:polymorphic_allocatordoesnotpropagateoncontainercopyassignment,moveassignment,orswap.Asaresult,moveassignmentofapolymorphic_allocator-usingcontainercanthrow,andswappingtwopolymorphic_allocator-usingcontainerswhoseallocatorsdonotcomp

c++ - 未定义对 avcodec_alloc_context 的引用但 ffmpeg 链接器顺序正确吗?

我想构建静态链接到libavcodec和libavformat的静态链接可执行文件。静态ffmpeg库是用以下方法构建的:./configure--enable-static--enable-gpl--enable-nonfree--disable-vaapi--disable-libopus--prefix=myBuild--disable-swresample链接器设置如下:g++-O2-static-omyBinmyBin-myBin.osomeotherlibraries.a-L/ffmpeg/myBuild/lib-lavformat-lavcodec-lavutil-lrt

C++ 拼图 : Prevent heap allocation for derived classes, 允许自动和静态

目标:Base类的对象可以是静态的、自动的、直接在堆上分配的,并参与在任何地方分配的复合对象对于任何将Base作为可访问祖先的Derived类,对象可以是静态的或自动的并参与组合,但可能不直接在堆上分配例子:#include"Base.h"#include"Derived.h"{staticBasesb;//OKBaseab,*hb=newBase;//OKstaticDerivedsd;//OKDerivedad;//OKDerived*pd=&ad;//OKDerived*hd=newDerived;//Compileerror,linkerror,//test-unitexcep

c++ - 虚拟内存耗尽 : Cannot allocate memory

我在ubuntu12.10上编译失败,可用内存为300mb(总计750mb,MySQL为350mb),1.5ghz,我正在尝试将wt的基本helloworld文件重新加工成一个简单的ajax页面。我很确定这根本不是内存问题,因为我能够使用g++-O3-ohellohello.C-lwtfcgi-lwt-lboost_signals编译原始的hello.C文件。.自从我撕掉了HelloApplication::HelloApplication(constWEnvironment&env):WApplication(env)的内脏后,我确定我搞砸了C++并放入Wt::Json示例中的示例H

android - C++ 运算符 new 和 new[] 会在 Android 上抛出 std::bad_alloc 吗?

分配内存失败会抛出异常吗?我最近才知道Android支持异常。 最佳答案 我下载了ndk并在文档文件夹CPLUSPLUS-SUPPORT.HTML中找到了它。I.C++Exceptionssupport:TheNDKtoolchainsupportsC++exceptions,sinceNDKr5,howeverallC++sourcesarecompiledwith-fno-exceptionssupportbydefault,forcompatibilityreasonswithpreviousreleases.Toenable

c++ - 编译器找不到 "aligned_alloc"函数

尝试获得一个可移植的函数以在具有对齐特征的堆上进行分配。找到“aligned_alloc”,我认为它在stdlib.h中,但gcc似乎不这么认为error:'aligned_alloc'wasnotdeclaredinthisscope使用带有标志-std=c++11-m64的gcc尝试导入#include#include 最佳答案 aligned_alloc在C11中定义。它(还)没有为C++定义,尽管它可能会出现在C++17中。(也就是说,它不在标准C库中预期在标准C++库中可用的(当前)209个函数列表中。请参阅C++标准的附

c++ - 奇怪的 std::bad_alloc

据我所知,可以抛出std::bad_alloc的三个原因:进程请求的内存多于可提供的内存地址空间过于分散,无法满足对大块连续内存的请求堆管理数据结构已损坏我们的代码会遇到std::bad_alloc,但上述原因似乎都不适用。数据结构是一个存储为顶点std::list的图,其中每个顶点再次存储一个std::list的边,它是其中的一部分以及一些连续的数据。对于小图(由于在较大的block中分配更多内存时没有问题,因此应排除上述原因1.和2.。在某些部分,我们以一种非常容易出错的方式使用指针,因此我们可能会破坏堆数据结构。但是当在较小的实例上运行时,valgrind的memcheck报告我

c++ - 在带有 std::unordered_map 的 std::scoped_allocator_adaptor 中使用自定义分配器

我正在尝试将一个简单的内存池分配器与std::unordered_map一起使用。我在std::string和std::vector中似乎成功地使用了同一个分配器。我希望unordered_map(和vector)中包含的项目也使用此分配器,因此我将我的分配器包装在std::scoped_allocator_adaptor中。简化定义集:templateusingmm_alloc=std::scoped_allocator_adaptor>;usingmm_string=std::basic_string,mm_alloc>;usingmm_vector=std::vector>;us

c++ - 一些 STL 容器的 std::allocator 不匹配

使用不匹配的std::allocator特化(当然,除了它对void的特化)作为STL容器(不是所有容器)的模板参数在技术上是否有效,但下面列举的加上unordered_(multi)map/set)?以下代码编译正常。#include#include#include#include#includeintmain(){structA{booloperator>l;std::forward_list>fl;std::deque>d;std::set,std::allocator>s;std::multiset,std::allocator>ms;std::map,std::allocat

C++ 使用 getline() 打印 : pointer being freed was not allocated in XCode

我正在尝试使用std:getline()但出现了一个奇怪的运行时错误:malloc:*errorforobject0x10000a720:pointerbeingfreedwasnotallocated*setabreakpointinmalloc_error_breaktodebug这是产生此错误的代码://main.cpp#include#includeintmain(intargc,char*constargv[]){std::istringstreammy_str("demostringwithspaces");std::stringword;while(std::getlin