没有动态内存分配的STD :: MAP ... [英] STD::MAP without dynamic memory allocation...

查看:207
本文介绍了没有动态内存分配的STD :: MAP ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我需要为没有动态内存分配的指定数量的元素创建STD :: MAP结构.只是在创建MAP的那一刻,分配了内存,之后就无法使用内存了.


已经阅读了有关分配器的信息,但无法使用它.

在某些站点上了解到它不适用于MAP,仅适用于Vector和其他,但发现是在"fast_pool_allocator"类中实现的.

请帮助=)

Good day to everybody.
I need to create the STD::MAP structure for a specified number of elements without dynamic memory allocation. Just at the moment of creation MAP allocate memory and after that didn''t work with memory.


Already read about allocator, but couldn''t use it.

On some sites read that it''s doesn''t work with MAP, only with Vector and other, but found that is implemented in the class "fast_pool_allocator".

Please help =)

推荐答案

如果您知道映射中元素的最大数量,则可以调整分配器以从堆栈中选择内存,没有动态分配,但是请注意堆栈限制(此映射不应在线程之间共享.)
如果您有这些要求,请提供更具体的答案.
If you know the maximum number of element in your map, then you can tweak your allocator to pick memory from stack,, no dynamic allocation but you be careful with stack limits (this map should not be shared between threads.)
If these are your requirements the reply for more specific answer.


我认为只有使用boost库才有可能.
http://www.boost.org/ [ ^ ]
我不确定其许可证.请浏览该网站.
uisng boost :: assign命名空间,如下所示

I think it is possible only with boost libraries.
http://www.boost.org/[^]
I am not sure about its license. Please go through the site.
uisng boost::assign name space it is possible as below

map<int,int> next = map_list_of(1,2)(2,3);


希望这就是您想要的


hope this is what you were looking for


这篇关于没有动态内存分配的STD :: MAP ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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