草庐IT

malloc_ptr_t

全部标签

c++ - 为什么英特尔的 icc 的 malloc 比 new 慢 7 倍?

我在分配float组时对malloc与new进行了基准测试。我的理解是malloc执行的操作是new执行的操作的子集——malloc只是分配,但new分配和构造,尽管我不确定这对于原语是否有意义。使用gcc的基准测试结果给出了预期的行为。malloc()更快。甚至有一些问题与这个问题相反。使用iccmalloc可以比new慢7倍。怎么可能?!接下来的一切只是基准测试过程的细节。对于基准测试,我使用了最近描述的协议(protocol)byIntel.这是我的结果。使用GNU的gcc分配4000个float的数组时经过的时钟周期:newmemoryallocation,cycles1216

c++ - 这篇关于shared_ptr的use_count()的Standardese是什么意思?

在试图解决thisquestion中显示的问题时我发现自己陷入了[util.smartptr.shared]/4中的以下句子:[...]Changesinuse_count()donotreflectmodificationsthatcanintroducedataraces.我不明白我应该怎么读,我会得出什么结论。以下是一些解释:调用use_count()不会引入数据竞争(但这应该由该函数的const-ness以及相应的库范围保证来保证)use_count()返回的值不受(“不反射(reflect)”?)需要原子性或同步的操作结果的影响(但这些相关操作是什么?)use_count()

c++ - 这篇关于shared_ptr的use_count()的Standardese是什么意思?

在试图解决thisquestion中显示的问题时我发现自己陷入了[util.smartptr.shared]/4中的以下句子:[...]Changesinuse_count()donotreflectmodificationsthatcanintroducedataraces.我不明白我应该怎么读,我会得出什么结论。以下是一些解释:调用use_count()不会引入数据竞争(但这应该由该函数的const-ness以及相应的库范围保证来保证)use_count()返回的值不受(“不反射(reflect)”?)需要原子性或同步的操作结果的影响(但这些相关操作是什么?)use_count()

c++ - 标准 <memory> 文件中 boost::shared_ptr 和 std::shared_ptr 之间的区别

我想知道boost::shared_ptr之间是否有任何区别和std::shared_ptr在标准中找到文件。 最佳答案 std::shared_ptr是tr1::shared_ptr的C++0x形式,boost的boost::shared_ptr应该表现一样。然而,std::shared_ptr,在符合C++0x标准的实现中,应该/可能对shared_ptr类有更方便的行为,如所述在以下链接中:Differencesbetweendifferentflavoursofshared_ptrhttp://en.wikipedia.or

c++ - 标准 <memory> 文件中 boost::shared_ptr 和 std::shared_ptr 之间的区别

我想知道boost::shared_ptr之间是否有任何区别和std::shared_ptr在标准中找到文件。 最佳答案 std::shared_ptr是tr1::shared_ptr的C++0x形式,boost的boost::shared_ptr应该表现一样。然而,std::shared_ptr,在符合C++0x标准的实现中,应该/可能对shared_ptr类有更方便的行为,如所述在以下链接中:Differencesbetweendifferentflavoursofshared_ptrhttp://en.wikipedia.or

c++ - LocalAlloc 与 GlobalAlloc 与 malloc 与 new

我已经在各种链接上搜索过这个,但仍然存在疑问。我不明白LocalAllocvsGlobalAllocvsmallocvsnew内存分配的区别。我已经浏览了MSDN的这个链接:ComparingMemoryAllocationMethods请解释以下语句:Themallocfunctionhasthedisadvantageofbeingrun-timedependent.Thenewoperatorhasthedisadvantageofbeingcompilerdependentandlanguagedependent 最佳答案

c++ - LocalAlloc 与 GlobalAlloc 与 malloc 与 new

我已经在各种链接上搜索过这个,但仍然存在疑问。我不明白LocalAllocvsGlobalAllocvsmallocvsnew内存分配的区别。我已经浏览了MSDN的这个链接:ComparingMemoryAllocationMethods请解释以下语句:Themallocfunctionhasthedisadvantageofbeingrun-timedependent.Thenewoperatorhasthedisadvantageofbeingcompilerdependentandlanguagedependent 最佳答案

c++ - 在 map 中使用自定义删除器存储 unique_ptr

为什么这不起作用?#include#includevoiddeleter(int*i){deletei;}std::map>m;voidfoo(int*i){m[0]=std::unique_ptr(i,&deleter);}查看无法理解的编译错误https://godbolt.org/z/Uhp9NO.Infileincludedfrom:1:Infileincludedfrom/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/map:61:Inf

c++ - 在 map 中使用自定义删除器存储 unique_ptr

为什么这不起作用?#include#includevoiddeleter(int*i){deletei;}std::map>m;voidfoo(int*i){m[0]=std::unique_ptr(i,&deleter);}查看无法理解的编译错误https://godbolt.org/z/Uhp9NO.Infileincludedfrom:1:Infileincludedfrom/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/map:61:Inf

c++ - 如果 unique_ptr 需要存储删除器,它怎么能没有开销?

首先看看C++Primer说的unique_ptr和shared_ptr:16.1.6美元。效率和灵activeWecanbecertainthatshared_ptrdoesnotholdthedeleterasadirectmember,becausethetypeofthedeleterisn’tknownuntilruntime.Becausethetypeofthedeleterispartofthetypeofaunique_ptr,thetypeofthedeletermemberisknownatcompiletime.Thedeletercanbestoreddire