草庐IT

swig_shared_ptr

全部标签

java - 使用 SWIG 返回一个 java 对象数组

我正在使用SWIG为C++库编写JNI包装器。库中的一种方法返回分配内存中的结构数组:typedefstruct{intid;doublex;doubley;}DataStruct;intget_all_data(longref,DataStruct**ppdata,size_t*psize){//...preparethedatabytheref*ppdata=(DataStruct*)malloc(sizeof(DataStruct)*size);*psize=size;return0;}Java中的方法签名应如下所示:nativeDataStruct[]get_all_data(

c++ - 如何深入研究 shared_ptr [Netbeans、clang++、gdb]

我正在使用NetbeansC++8.0.2clang++(Ubuntuclang版本3.6.0-2ubuntu1(tags/RELEASE_360/final)(基于LLVM3.6.0))gdb(GNUgdb(Ubuntu7.9-1ubuntu1)7.9)在我的“C++简单测试”中,每当我检查一个shared_ptr变量时,我看到的所有值都是:std::shared_ptr(count1,weak0)0x64d3a0或类似的。无法深入了解它实际指向的值。即使变量窗口中的TreeView显示了其中一个扩展器图标,当我单击它时它也会消失。当我尝试取消引用它或在“表达式”窗口中调用它的get

c++ - 防止对 std::unique_ptr 的不安全取消引用

摘自cppcon2015的幻灯片:unique_ptrf(){autoa=make_unique();returna;}//Whydoesthisevencompile?constA&dangling=*f();//BOOM!!!use(dangling);我的问题是:对于*this的右值引用,这可以解决吗?我在cppreference的规范中看到:typenamestd::add_lvalue_reference::typeoperator*()const;问题:不允许operator*用于右值unique_ptr并且只对左值unique_ptr取消引用有效吗?仍然有有效的用例来保持

c++ - 如何使用 Cereal 序列化 boost::ptr_vector?

是否可以使用cereal序列化boost::ptr_vector实例?如果是,怎么办? 最佳答案 绝对有可能。您可以在存档和指针类型上创建外部save()和load()模板函数,如下所示:#include#include#include#include#include//Sampleserializableobject.structMyRecord{std::strings_;MyRecord(conststd::strings=std::string()):s_(s){}templatevoidserialize(Archive&

c++ - 使用 std::weak_ptr 和别名构造函数打破循环引用:听起来还是有问题?

我还没有在任何主要的C++论坛/博客(例如GotW)上找到以下打破循环引用的方法,所以我想问一下该技术是否已知,其优缺点是什么?classNode:publicstd::enable_shared_from_this{public:std::shared_ptrgetParent(){returnparent.lock();}//thegetterfunctionsensurethat"parent"alwaysstaysalive!std::shared_ptrgetLeft(){returnstd::shared_ptr(shared_from_this(),left.get())

c++ - 为用户定义类型的 shared_ptr 专门化标准库函数是否合法?

标准说明了以下关于从标准库中专门化模板的内容(通过Whatcanandcan'tIspecializeinthestdnamespace?)Aprogrammayaddatemplatespecializationforanystandardlibrarytemplatetonamespacestdonlyifthedeclarationdependsonauser-definedtypeandthespecializationmeetsthestandardlibraryrequirementsfortheoriginaltemplateandisnotexplicitlyprohi

带有 shared_ptr 的 C++ openmp

这是一个困扰我的最小例子#include#include#include"omp.h"classA{public:A(){std::coutsim(std::make_shared());}for(unsignedinti=0;isim(std::make_shared());}}如果我多次运行这段代码,我可能会得到这样的结果:0xea33080xea32d80xea33380x7f39f80008c80xea33380xea33380xea33380xea3338我意识到最后4个输出的数量总是相同的字符(8)。但由于某种原因,它发生(不总是)一个或多个第四个输出包含更多(14)个字符

c# - 为包装 C++ 的 swig 生成的 C# 生成 doxygen 注释

我有一个用C++编写的项目,我也在其中使用swig生成一些C#包装器。C++代码使用Doxygen风格的注释来注释类和函数。是否可以让Swig获取这些doxygen注释并为C#包装器类和函数生成doxygen注释? 最佳答案 目前,SWIG根本不解析代码注释,包括Doxygen文档。几年来有一个SWIG分支正在开发中,以使SWIG能够处理Doxygen注释,但即使是目前(AFAIK)也只能将它们映射到Java和Python文档。因此,目前最好的选择是从C++源代码中提取Doxygen文档并将其插入到SWIG生成的包装器中。要了解如何

C++11 将 shared_ptr 转换为 vector 和类

我正在尝试将转换应用到shared_ptr并存储到shared_ptr,同时还在类中使用函数。我创建了这个例子:#include#include#include#includeusingnamespacestd;classMyClass{public:intfactor=0;MyClass(constintfactor_):factor(factor_){}shared_ptr>mult(shared_ptr>numbers){shared_ptr>result(newvector());transform(numbers->begin(),numbers->end(),result-

c++ - std::shared_ptr 内部结构,弱计数超过预期

合一episode(35:00)高级STL系列,StephanTLavavej展示了_Weaks,其值为0的计数器决定何时删除_Ref_count结构,等于存活的数量weak_ptr,如果存在shared_ptr则加1。他解释说这是必要的,因为线程安全:如果_Weaks仅等于weak_ptr的数量,那么当最后一个weak_ptr超出范围时它还需要检查_Uses,即事件shared_ptr的计数器,以检查是否可以删除_Ref_count。由于缺乏原子性,这是NotAcceptable。假设_Uses=活跃的shared_ptr数量,_Weaks=活跃的weak_ptr数量,想象一下我们有