草庐IT

malloc_ptr_t

全部标签

c++ - 使用 Boost Python & std::shared_ptr

我正在尝试让BoostPython与std::shared_ptr很好地配合使用。目前,我收到此错误:Traceback(mostrecentcalllast):File"test.py",line13,incomp.place_annotation(circle.centre())TypeError:Noto_python(by-value)converterfoundforC++type:std::shared_ptr来自调用circle.centre(),它返回一个std::shared_ptr。我可以将每个std::shared_ptr更改为boost::shared_ptr(

c++ - 使用 Boost Python & std::shared_ptr

我正在尝试让BoostPython与std::shared_ptr很好地配合使用。目前,我收到此错误:Traceback(mostrecentcalllast):File"test.py",line13,incomp.place_annotation(circle.centre())TypeError:Noto_python(by-value)converterfoundforC++type:std::shared_ptr来自调用circle.centre(),它返回一个std::shared_ptr。我可以将每个std::shared_ptr更改为boost::shared_ptr(

c++ - unique_ptr、pimpl/forward 声明和完整定义

我已经查看了问题here和here,但仍然无法找出问题所在。这是调用代码:#include"lib.h"usingnamespacelib;intmain(constintargc,constchar*argv[]){return0;}这是库代码:#ifndeflib_h#definelib_h#include#include#includenamespacelib{classFoo_impl;classFoo{public:Foo();~Foo();private:Foo(constFoo&);Foo&operator=(constFoo&);std::unique_ptrm_imp

c++ - unique_ptr、pimpl/forward 声明和完整定义

我已经查看了问题here和here,但仍然无法找出问题所在。这是调用代码:#include"lib.h"usingnamespacelib;intmain(constintargc,constchar*argv[]){return0;}这是库代码:#ifndeflib_h#definelib_h#include#include#includenamespacelib{classFoo_impl;classFoo{public:Foo();~Foo();private:Foo(constFoo&);Foo&operator=(constFoo&);std::unique_ptrm_imp

c++ - 如何在 C++ 中声明使用 malloc 创建的数组是 volatile

我认为以下将给我10个volatile整数volatileintfoo[10];但是,我认为以下内容不会做同样的事情。volatileint*foo;foo=malloc(sizeof(int)*10);如果我对此有误以及如何使用malloc获得易变的项目数组,请纠正我。谢谢。 最佳答案 intvolatile*foo;从右到左读取“foo是一个指向volatileint的指针”所以无论你通过foo访问什么int,这个int都会是volatile。附言int*volatilefoo;//"fooisavolatilepointert

c++ - 如何在 C++ 中声明使用 malloc 创建的数组是 volatile

我认为以下将给我10个volatile整数volatileintfoo[10];但是,我认为以下内容不会做同样的事情。volatileint*foo;foo=malloc(sizeof(int)*10);如果我对此有误以及如何使用malloc获得易变的项目数组,请纠正我。谢谢。 最佳答案 intvolatile*foo;从右到左读取“foo是一个指向volatileint的指针”所以无论你通过foo访问什么int,这个int都会是volatile。附言int*volatilefoo;//"fooisavolatilepointert

c++ - 当 malloc()-ing 相同的结构时,如何在结构中使用 C++ 字符串?

我编写了以下示例程序,但它因段错误而崩溃。问题似乎在于在结构中使用malloc和std::strings。#include#include#includestructexample{std::stringdata;};intmain(){example*ex=(example*)malloc(sizeof(*ex));ex->data="helloworld";std::coutdata我不知道如何使它工作。如果甚至可以使用malloc()和std::strings有什么想法吗?谢谢,博达·赛多。 最佳答案 您不能在C++中mall

c++ - 当 malloc()-ing 相同的结构时,如何在结构中使用 C++ 字符串?

我编写了以下示例程序,但它因段错误而崩溃。问题似乎在于在结构中使用malloc和std::strings。#include#include#includestructexample{std::stringdata;};intmain(){example*ex=(example*)malloc(sizeof(*ex));ex->data="helloworld";std::coutdata我不知道如何使它工作。如果甚至可以使用malloc()和std::strings有什么想法吗?谢谢,博达·赛多。 最佳答案 您不能在C++中mall

c++ - 关于weak_ptr的线程安全

std::shared_ptrg_s=std::make_shared(1);voidf1(){std::shared_ptrl_s1=g_s;//readg_s}voidf2(){std::shared_ptrl_s2=std::make_shared(3);std::threadth(f1);th.detach();g_s=l_s2;//writeg_s}关于上面的代码,我知道读取和写入相同shared_ptr的不同线程会导致竞争条件。但是weak_ptr呢?下面的代码中是否有任何竞争条件?(我的平台是微软VS2013。)std::weak_ptrg_w;voidf3(){std:

c++ - 关于weak_ptr的线程安全

std::shared_ptrg_s=std::make_shared(1);voidf1(){std::shared_ptrl_s1=g_s;//readg_s}voidf2(){std::shared_ptrl_s2=std::make_shared(3);std::threadth(f1);th.detach();g_s=l_s2;//writeg_s}关于上面的代码,我知道读取和写入相同shared_ptr的不同线程会导致竞争条件。但是weak_ptr呢?下面的代码中是否有任何竞争条件?(我的平台是微软VS2013。)std::weak_ptrg_w;voidf3(){std: