上面的是,最后只是不够快。下面生成1 e6 uuid为matlab字符串数组,在2.6 s在我的机器上。
好多了。
试试这个;
#包括< iostream >
#包括<字符串>
#包括<列表>
#包括“MatlabDataArray.hpp”
#包括“C: / temp / fastUUID / boost_1_71_0 / boost_1_71_0 /提高/ uuid / uuid.hpp”/ / uuid类
#包括“C: / temp / fastUUID / boost_1_71_0 / boost_1_71_0 /提高/ uuid / uuid_generators.hpp”/ /发电机
#包括“C: / temp / fastUUID / boost_1_71_0 / boost_1_71_0 /提高/ uuid / uuid_io.hpp”/ /流媒体运营商等。
#包括“C: / temp / fastUUID / boost_1_71_0 boost_1_71_0 /提高/ lexical_cast.hpp”/ /流媒体运营商等。
#包括“mex.hpp”
#包括“mexAdapter.hpp”
使用名称空间matlab:数据;
使用matlab:墨西哥人::ArgumentList;
使用名称空间性病;
/ /需要安装https://www.boost.org/
/ / matlabcpp编译器
/ /最后墨西哥人makeUuidArray。cpp的":\ temp \ fastUUID \ boost_1_71_0 \ boost_1_71_0
类MexFunction:公共matlab::墨西哥人:函数{
公众:
无效操作符()(ArgumentList输出,ArgumentList输入){
checkArguments(输出,输入);
常量输入int numIds = [0] [0];
ArrayFactory工厂;
boost:: uuid: random_generator发生器;
boost:: uuid: uuid uuid1;
/ /三个变量的字符串向量、tempstring tempUUID
TypedArray < MATLABString >结果=工厂。createArray < MATLABString > ({numIds, 1});
为(汽车elem:结果){
uuid1 =发生器();
boost:: lexical_cast elem = < std:: string > (uuid1);
}
输出[0]=结果;
}
无效checkArguments (ArgumentList输出,ArgumentList输入){
std::要查看< matlab::引擎::MATLABEngine > matlabPtr = getEngine ();
ArrayFactory工厂;
/ /检查第一输入参数
如果(输入[0]. gettype () ! = ArrayType::双| |
输入[0]. gettype () = = ArrayType:: COMPLEX_DOUBLE | |
输入[0].getNumberOfElements () ! = 1)
{
matlabPtr - >函数宏指令(u“错误”,
0,
std::向量数组< > ({factory.createScalar (“首先输入必须标量双”}));
}
/ /检查数量的输出
如果(outputs.size () > 1) {
matlabPtr - >函数宏指令(u“错误”,
0,
std::向量数组< > ({factory.createScalar (“只有一个输出返回”}));
}
}
};