首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

对于std :: map,如果必须调整容器大小并且内存不可用,插入的行为方式如何?

在std::map中,插入的行为方式通常是基于动态规划,即将已插入的元素存储在一个二叉搜索树的节点中,这个节点会随着元素的不断插入而自增。

如果必须调整容器大小,并且内存不可用,那么可能会尝试通过重新计算整个二叉搜索树的方式来实现插入操作的降级。这个过程可能会导致插入操作变得非常慢,因为需要遍历整个二叉搜索树来找到合适的插入位置。

如果内存确实不够了,那么std::map可能会尝试将元素从容器中删除,并将它们放入一个临时容器中直到内存得到释放。

总的来说,std::map会尽力避免内存不足的情况,但是如果必须进行调整容器大小,则会使用一些策略来尝试解决问题。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

C++ map 和 hashmap 区别

1. stl map is an associative array where keys are stored in sorted order using balanced trees. while hash_map is a hashed associated container, where keys are not stored in an ordered way. key, value pair is stored using a hashed function.        2. insertion and lookup takes ologn time in map, also performance would degrade as the key size increases. mainly balance operations on large key ranges would kill performance. while lookup is very efficient o(1) in hash_map.        3. map is useful where you want to store keys in sorted order, hash_map is used where keys order is not important and lookup is very efficient.        4. one more difference is map has the important property that inserting a new element into a map does not invalidate iterators that point to existing elements. erasing an element from a map also does not invalidate any iterators. performance would mostly be o(lgn) due to the implementation of a balanced tree. for map custom objects you would need at the minimum the following operators to store data in a map "<" ">" "==" and of course the other stuff for deep copy.

00

一文带你掌握Kubernetes VPA(Pod纵向自动扩缩)

之前的文章我们介绍了HPA(Horizontal Pod Autoscaler)的实现,HPA一般被称为横向扩展,与HPA不同的Vertical Pod Autoscaler ( VPA ) 会自动调整 Pod 的 CPU 和内存属性,被称为纵向扩展。VPA可以给出服务运行所适合的CPU和内存配置,省去估计服务占用资源的时间,更合理的使用资源。当然,VPA也可根据资源的使用情况“调整”pod的资源。这里的调整我们用了双引号,因为他的实现机制是重建而不是动态增加。下面是一个实际的例子:假设我的memory limits是100Mi,但是现在已经用到了98Mi,如果再大的话就oom了,此时vpa会在垂直方向上提升你的memory limits的大小。这种vpa比较适合一些资源消耗比较大的应用,例如es,你给大了资源浪费,给小了,又不够。所以vpa就派上用场了。当然,vpa不像hpa默认集成在k8s里面的,需要你自己去配置的。

02
领券