gpt4 book ai didi

c++ - map 对象在方法调用期间被复制

转载 作者:行者123 更新时间:2023-11-28 00:12:05 25 4
gpt4 key购买 nike

功能:

void Function(int* integer, map<unsigned short, unsigned short> firstMap, map<int, unsigned char> secondMap);

每当我像这样从另一个类(class)调用它时......

Object->Function(integer, firstMap, secondMap);

调用

std::_Tree<std::_Tmap_traits<int,unsigned char,std::less<int>,std::allocator<std::pair<int const ,unsigned char> >,0> >::_Tree<std::_Tmap_traits<int,unsigned char,std::less<int>,std::allocator<std::pair<int const ,unsigned char> >,0> > 

进入 xtree 被调用的方法是:

_Tree(const _Myt& _Right)
: _Mybase(_Right.key_comp(), _Right.get_allocator())
{ // construct tree by copying _Right
_Init();
_TRY_BEGIN
_Copy(_Right);
_CATCH_ALL
_Tidy();
_RERAISE;
_CATCH_END
}

这是在做什么?为什么叫它?是否正在复制 map ?使用 very sleepy 我发现我的周期时间的 20% 被这个调用用完了。

最佳答案

我认为您可能希望通过引用而不是通过值来传递 map

void Function(int* integer, map<unsigned short, unsigned short>& firstMap, map<int, unsigned char>& secondMap);

注意添加的“&”。

您可能感兴趣的 C++11 附加功能是 moving in place (如果变量只是临时使用)。

关于c++ - map 对象在方法调用期间被复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32490244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com