protobuf 消息定义:使用 protobuf-3.6.1
syntax = "proto3";
message UserMessage {
message Int64List {
repeated int64 value = 1;
};
int64 uid = 1;
int64 gid = 2;
repeated int32 cat = 3;
map<string, int32> simple_map = 4;
map<string, Int64List> map_list = 5;
};
Run Code Online (Sandbox Code Playgroud)
cp代码:
UserMessage message;
auto m = message.mutable_simple_map();
(*m)["aaa"] = 2;
(*m)["bbb"] = 5;
{
std::cout << message.ShortDebugString() << std::endl;
auto a = message.simple_map();
for (auto& b : a) {
std::cout << "new " << b.first << ":" << …Run Code Online (Sandbox Code Playgroud) 我正在使用Magick ++(IM 7.0.3平台:CentOS Linux 7.0版)将图像转换为gif.我从文件创建Image对象,问题是当我将9个png文件(每个50kb)转换为gif时,它只需要50ms.但当它转向9个jpg文件(每个20kb)时,它需要1900ms.背后的原因是什么?如何使用jpg文件加快速度?
for(int i = 2; i < argc-1; i++)
{
// I pass the file path from command line
cout << argv[i] << endl;
Image img(argv[i]);
img.animationDelay(delay);
img.magick("GIF");
frames.push_back(img);
}
long mergestart = getCurrentTime();
Magick::Blob tmpBlob;
Magick::writeImages(frames.begin(), frames.end(), &tmpBlob);
Run Code Online (Sandbox Code Playgroud) 我在下面有这些代码。const auto&在这种情况下有什么问题,它导致了意外的输出。
使用 gcc-4.8.5 编译时它工作正常,但使用 gcc-4.9.2 得到意外输出。
如果我删除&in const auto&,它可以在两个 gcc 版本中正常工作。
// max_dim is a protobuf filed: const auto max_dim = msg.max();
// cat2_num is an element in std::vector<int32_t>: const auto cat2_num = vec[i]
const auto& res_num = std::max(1, std::min(max_dim, cat2_num));
LOG(ERROR) << res_num << ", " << max_dim << ", " << cat2_num
<< ", " << std::max(1, std::min(max_dim, cat2_num));
Run Code Online (Sandbox Code Playgroud)
输出:
-1392522416, 3, 1, 1
2, 3, 2, 2
3, 3, 3, 3 …Run Code Online (Sandbox Code Playgroud)