草庐IT

HAVE_MALLOC_USABLE_SIZE

全部标签

c++ - std::string::max_size() 作为静态成员

为什么max_size不是std::string的静态成员?这可以编译,但我觉得奇怪的是所有字符串共有的属性只能通过字符串的实例访问:std::size_tmax_size=std::string().max_size();为什么会这样实现? 最佳答案 Whyisn'tmax_sizeastaticmemberofstd::string?因为max_size返回值取决于字符串实例内部使用的分配器实例。 关于c++-std::string::max_size()作为静态成员,我们在Stac

c++ - 对于具有默认分配器的标准容器,std::container::size_type 是否保证为 size_t?

喜欢:std::string::size_typestd::list::size_typestd::map::size_typestd::vector::size_type等等两者都是cplusplus.com和cppreference.com说他们通常是size_t,但它们是否真正、明确地保证为size_t的标准除非使用自定义分配器? 最佳答案 对于STL容器-不。[container.requirements.general]中标准的表96,其中列出了任何容器的容器要求X,解释得很清楚:但是,对于basic_string,siz

c++ - std::vector::resize(size_type) 需要 CopyInsertable?

这个问题是在我回答thisanotherquestion的时候提出的.N333723.3.6.3“vector容量”说(在770页):voidresize(size_typesz);Effects:Ifsz,equivalenttoerase(begin()+sz,end());.Ifsize(),appendssz-size()value-initializedelementstothesequence.Requires:TshallbeCopyInsertableinto*this.然而,clang++saysit'sokaythoughTisnotcopyable.我认为resiz

c++ - Pimpl with unique_ptr : Why do I have to move definition of constructor of interface to ".cpp"?

只要我不将构造函数(B)的定义移动到标题B.h中,代码就可以工作。B.hclassImp;//imp;B();//B.cpp#include"B.h"#include"Imp.h"B::B(){}~B::B(){}Imp.hclassImp{};Main.cpp(编译我)#include"B.h"Error:deletionofpointertoincompletetypeError:useofundefinedtype'Imp'C2027我能以某种方式理解必须将析构函数移动到.cpp,因为可能会调用Imp的解构:-deletepointer-of-Imp;//somethinglik

c++ - 制作 std::vector capacity>=N 和 size=0 的最佳方法?

给定一个std::vector,其大小和容量可以是任意的,将其大小更改为0并将容量更改为至少N(给定数字)的最佳做法是什么?我的直接想法是:voidf(vector&t,intN){t.clear();t.reserve(N);}但是我注意到了Areallocationisnotguaranteedtohappen,andthevectorcapacityisnotguaranteedtochange(whenstd::vector::cleariscalled).所以我想知道当原始容量大于给定的N时如何避免重新分配? 最佳答案 w

c++ - 为什么 GCC 中 std::list O(n) 的 size() 方法?

在GCC中,std::list的size()方法是O(n)。为什么?对于C++11,标准是size()oflistshouldbeO(1)但是在glibc中我们有以下内容:/usr/include/c++/4.6.3/bits/stl_list.htemplate>classlist:protected_List_base{...size_typesize()const{returnstd::distance(begin(),end());}问题是:为什么三年前的要求还没有在GCC中实现?编辑:gcc5改变了这一点:尽管以ABI改变为代价;这意味着使用gcc5.0编译的C++代码将无法

c++ - Visual C++ 运行时 malloc/free 会将内存返回给操作系统吗?

问题与Willmallocimplementationsreturnfree-edmemorybacktothesystem?非常相似,但我对Windows/MicrosoftVisualStudio的答案以及有关确切虚拟内存状态的详细信息感兴趣。请问VisualC++CRTfree将内存还给系统?关于虚拟内存分配,内存的确切状态是什么?对一个大内存块做free之后,block中的内存是committed,reserved,还是free?如果我调用_heapmin怎么办?免费后? 最佳答案 查看2010的源码,可以看到malloc/

c++ - 警告 C4251 : needs to have dll-interface to be used by clients of class

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:std::vectorneedstohavedll-interfacetobeusedbyclientsofclass'Xwarning这是我在该组中的第一篇文章。我正在创建一个DLL并在应用程序的主文件中调用它。代码编译正常,但出现以下错误:warningC4251:'PNCBaseClass::m_vAvailChannelsFromRx':class'std::vector'needstohavedll-interfacetobeusedbyclientsofclass'PNCBaseClass'3>w

具有非 size_t 整数的 std::array 的 C++ 模板参数推导

我正在尝试调整Avoidingstructinvariadictemplatefunction中提供的解决方案根据我的需要。但是,我无法理解G++的行为。考虑以下功能:templateintnextline(consttypenamestd::arrayar){return0;}然后调用nextline(std::array{1,0});与GCC提示不匹配eslong.cpp:Infunction‘intmain()’:eslong.cpp:10:38:error:nomatchingfunctionforcallto‘nextline(std::array)’nextline(std

c++ - 为什么随机访问迭代器的算术运算符接受/返回 int 而不是 size_t?

由于std::vector上的大多数操作都需要/返回size_t-这就是我用于索引的类型。但现在我已经启用所有编译器警告来修复一些我知道的有符号/无符号转换问题,这条消息让我感到惊讶:warningC4365:'argument':conversionfrom'size_t'to'__w64int',signed/unsignedmismatch它是由这段代码生成的:std::vectorv;size_tidx=0;v.insert(v.begin()+idx+1,0);我收到很多其他类似的消息,建议迭代器的算术运算符接受并返回int。为什么不是size_t?修复所有这些消息很痛苦,并