动态大小的文本对象,带有复制构造函数,平凡的赋值运算符和平凡的析构函数 [英] dynamically-sized text object with a copy constructor, a trivial assignment operator, and a trivial destructor
问题描述
我已经显示,表示 std :: string
不能插入 boost :: lockfree :: queue
。
I've been shown that a std::string
cannot be inserted into a boost::lockfree::queue
.
boost: :lockfree :: queue
太有价值了,不能放弃,因此我认为我可以使用非常大的固定长度 char
s根据要求(假设即使感到满意,因为我在学习如何满足这些要求方面遇到了麻烦),但是如果我想要大消息,那会占用内存。
boost::lockfree::queue
is too valuable to abandon, so I think I could use very large, fixed length char
s to pass the data according to the requirements (assuming that even satifies since I'm having trouble learning about how to satisfy these requirements), but that will eat up memory if I want large messages.
执行动态尺寸的文本对象存在一个复制构造函数,一个琐碎的赋值运算符和一个琐碎的析构函数?如果是这样,在哪里?如果不是这样,请概述如何显示一个。
Does a dynamically-sized text object with a copy constructor, a trivial assignment operator, and a trivial destructor exist? If so, where? If not, please outline how to manifest one.
推荐答案
动态大小类型很小的副本ctor / dtor是不可能的。有两种解决方法,可以使用固定大小的类型,也可以将指针存储在队列中:
A dynamically-size type with a trivial copy ctor/dtor is not possible. There are two solutions to your problem, use a fixed sized type, or store pointers in the queue:
boost::lockfree::queue<std::string*> queue(some_size);
// push on via new
queue.push(new std::string("blah"));
// pop and delete
std::string* ptr;
if(queue.pop(ptr))
{
delete ptr;
}
这篇关于动态大小的文本对象,带有复制构造函数,平凡的赋值运算符和平凡的析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!