草庐IT

libgnuSTL_shared

全部标签

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++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 使用 make_shared 时会发生什么

我很感兴趣这两行代码是否相同:shared_ptrsp(newint(1));//doubleallocation?shared_ptrsp(make_shared(1));//justoneallocation?如果这是真的,有人能解释一下为什么第二行只有一个分配吗? 最佳答案 第一种情况不执行双重分配,它执行两次分配,一个用于托管对象,一个用于shared_ptr控制block/。对于第二种情况,cppreference有一个很好的解释为什么std::make_shared通常只执行它所说的一次内存分配(强调我的future):

c++ - 使用 make_shared 时会发生什么

我很感兴趣这两行代码是否相同:shared_ptrsp(newint(1));//doubleallocation?shared_ptrsp(make_shared(1));//justoneallocation?如果这是真的,有人能解释一下为什么第二行只有一个分配吗? 最佳答案 第一种情况不执行双重分配,它执行两次分配,一个用于托管对象,一个用于shared_ptr控制block/。对于第二种情况,cppreference有一个很好的解释为什么std::make_shared通常只执行它所说的一次内存分配(强调我的future):

ruby - Ruby 编译时 "--enable-shared"是什么意思?

RVM将此标志用于./configure。它的意思是“为Ruby构建一个共享库”,但是我在哪里可以获得有关使用此编译标志时实际发生的更多信息? 最佳答案 它将创建libruby.so以便其他程序可以使用它,例如支持Ruby的Vim。 关于ruby-Ruby编译时"--enable-shared"是什么意思?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/18246610/

c++ - 为什么make_shared的大小是两个指针?

如代码here所示,make_shared返回的对象的大小是两个指针。但是,为什么make_shared不能像下面这样工作(假设T是我们要创建共享指针的类型):Theresultofmake_sharedisonepointerinsize,whichpointstoofallocatedmemoryofsizesizeof(int)+sizeof(T),wheretheintisareferencecount,andthisgetsincrementedanddecrementedonconstruction/destructionofthepointers.unique_ptrs只

c++ - 为什么make_shared的大小是两个指针?

如代码here所示,make_shared返回的对象的大小是两个指针。但是,为什么make_shared不能像下面这样工作(假设T是我们要创建共享指针的类型):Theresultofmake_sharedisonepointerinsize,whichpointstoofallocatedmemoryofsizesizeof(int)+sizeof(T),wheretheintisareferencecount,andthisgetsincrementedanddecrementedonconstruction/destructionofthepointers.unique_ptrs只