优化 - 返回过滤的元素作为std:vector< class>或std :: vector< Intrusive_ptr< class>>什么更好,为什么?
continue
I have some doubts about optimization regarding storing elements in vectors and getting information from them. Lets see the example
struct Entity
{
public:
Entity() = default;
bool isActive = false;
std::vector<SomeOtherClass> classesThatUseEntity;
}
class Manager
{
public:
Manager() = default;
const std::vector<Entity>& GetOnlyActiveEntity()
{
std::vector<Entity> value;
for (const auto& entity : differentSettings)
{
if (entity.isActive)
{
value.emplace_back();
}
}
return value;
}
private:
std::vector<Entity> differentSettings;
}
I was thinking of maybe using a vector of pointers to return values:std::vector< boost::intrusive_ptr<Entity>> GetOnlyActiveEntity()
with this, I got some comments from colleagues that the vector of pointers, in this case, is not the smart option because of heap fragmentation, but I am not sure that this comment is legit. What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论