重新分配标准分配器 [英] Realloc- in Standard allocator

查看:63
本文介绍了重新分配标准分配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在 std :: vector 中使用的标准分配器接口,是否支持重新分配?我有一个相当具体的用例,其中直接进行 realloc 的分配要比分配,移动和释放的效率要高得多.

For the Standard allocator interface for use in, say, std::vector, is re-allocation supported? I have a rather specific use-case in which being able to realloc directly would be much more efficient than allocating, moving, and freeing.

对不起-我绝对不打算调用 actual realloc ,我的意思是具有这些语义的函数.实际上,我在后台分配了一个堆栈,如果我在堆栈之外分配了更多内存,那么我将无法释放其下方的内存,这是一种总浪费,因为无论如何都无需再次分配连续的可用空间.因此,如果可以要求我在一个步骤中进行重新分配,那么我可以避免首先不得不分配一些东西并浪费一些内存,其次可以移动所有 vector 的内容.

Sorry- I have absolutely no intention of calling the actual realloc, I meant a function with those semantics. Effectively, I'm allocating off a stack in the background, and if I allocate more off the stack, then I can't free the memory underneath it, which is a total waste because there's no need to allocate again anyway as there's plenty of contiguous free space available. Thus, if I could be asked to reallocate in a single step, then I could avoid having to firstly, allocate some stuff and waste some memory, and secondly, move all the contents of the vector.

推荐答案

我们尝试了但失败了:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1953.html

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2045.html

我知道你的意思.;-)

I know what you meant. ;-)

这篇关于重新分配标准分配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆