搜索基于堆栈的容器 [英] Searching for stack based containers

查看:65
本文介绍了搜索基于堆栈的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨列表,

大多数STL容器都将数据存储在堆上。 (虽然有些

std :: string实现是值得注意的例外)当然,使用

堆作为存储会增加灵活性并允许处理

更大量的数据。但是,有些情况下,由于至少两个原因,这会导致效率低下:A)分配和

堆上的解除分配要慢得多。 B)堆栈上的内存访问是

更多缓存友好。


以上事实让我想尝试使用类似STL的容器

能够将他们的数据存储在堆栈中。有人熟悉这样的

容器实现吗?关于他们的任何意见?


提前致谢,

Jim Xochellis

Hi list,

Most STL containers are storing their data on the heap. (although some
std::string implementations are notable exceptions) Of course, using
the heap as storage increases flexibility and allows the handling of
much bigger amounts of data. However, there are cases where this turns
out to be inefficient for at least two reasons: A) Allocations and
deallocations on heap are much slower. B) Memory access on stack is
more cache friendly.

The above facts make me want to try using STL like containers which
are able to store their data on stack. Is anybody familiar with such
container implementations? Any opinions about them?

Thanks in advance,
Jim Xochellis

推荐答案

jimxoch写道:
jimxoch wrote:

大多数STL容器将其数据存储在堆上。 (虽然有些

std :: string实现是值得注意的例外)当然,使用

堆作为存储会增加灵活性并允许处理

更大量的数据。但是,有些情况下,由于至少两个原因,这会导致效率低下:A)分配和

堆上的解除分配要慢得多。 B)堆栈上的内存访问是

更多缓存友好。


以上事实让我想尝试使用类似STL的容器

能够将他们的数据存储在堆栈中。有人熟悉这样的

容器实现吗?关于他们的任何意见?
Most STL containers are storing their data on the heap. (although some
std::string implementations are notable exceptions) Of course, using
the heap as storage increases flexibility and allows the handling of
much bigger amounts of data. However, there are cases where this turns
out to be inefficient for at least two reasons: A) Allocations and
deallocations on heap are much slower. B) Memory access on stack is
more cache friendly.

The above facts make me want to try using STL like containers which
are able to store their data on stack. Is anybody familiar with such
container implementations? Any opinions about them?



大量固定大小的矢量(比如K维几何)必须使用内联数组来存储它们。我对

那些没有真正的看法,我也不会想到任何其他容器实际上会有他们的存储基于堆栈。


如果您想进行实验,我会推测任何容器

与您的自定义分配器预先分配一定数量的

房间堆叠然后让你重复使用那个内存应该是一个不错的模型。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

Plenty of fixed-size vectors (like for K-dimensional geometry) must
use inline arrays for their storage. I have no real opinion about
those, and I can''t think of any other containers that would actually
have their storage "stack based".

If you would like to experiment, I''d speculate that any container
with your custom allocator that preallocates a certain amount of
room "on stack" and then lets you reuse that memory should be a good
enough model.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


jimxochaécrit:
jimxoch a écrit :

嗨列表,


大多数STL容器正在存储他们的数据堆。 (虽然有些

std :: string实现是值得注意的例外)当然,使用

堆作为存储会增加灵活性并允许处理

更大量的数据。但是,有些情况下,由于至少两个原因,这会导致效率低下:A)分配和

堆上的解除分配要慢得多。
Hi list,

Most STL containers are storing their data on the heap. (although some
std::string implementations are notable exceptions) Of course, using
the heap as storage increases flexibility and allows the handling of
much bigger amounts of data. However, there are cases where this turns
out to be inefficient for at least two reasons: A) Allocations and
deallocations on heap are much slower.



在一般情况下哪个不是问题。如果它变成一个,你可以在分析后相应地调整。

Which in the general case is not a problem. And if it becomes one, you
can adapt accordingly after profiling.


B)堆栈上的内存访问更加缓存友好。
B) Memory access on stack is more cache friendly.



真的吗?也许在堆栈缓存的情况下。并且假设您的缓存很大

足以容纳您的容器加上部分堆栈。

Really ? Perhaps in case of stack cache. And supposing your cache is big
enough to hold your container plus part of the stack.


以上事实让我想尝试使用类似STL的容器,它们能够将数据存储在堆栈中。有人熟悉这样的

容器实现吗?关于他们的任何意见?
The above facts make me want to try using STL like containers which
are able to store their data on stack. Is anybody familiar with such
container implementations? Any opinions about them?



* STL喜欢*容器不需要,你可以直接使用STL和

自定义分配器。但是,恕我直言,我不会期待一个伟大的改进

,因为你必须重新实现类似堆的分配算法。


唯一的例外在某些特定情况下会使用已经建议的池/ shunk

方案(参见例如提升)。

Michael

*STL like* containers are not needed, you can directly use the STL with
a custom allocator. However, IMHO I wouldn''t expect a great improovement
since you would have to re-implement a heap-like allocation algotithm.

The only exception would be in some specific cases to use a pool/shunk
scheme which is already proposed (see boost for exemple).
Michael


jimxoch写道:
jimxoch wrote:

>

以上事实让我想尝试使用STL之类的容器

能够将他们的数据存储在堆栈中。有人熟悉这样的

容器实现吗?关于它们的任何意见?
>
The above facts make me want to try using STL like containers which
are able to store their data on stack. Is anybody familiar with such
container implementations? Any opinions about them?



TR1提供了一个数组模板,它将其内容放在堆栈上。它

拥有一个固定大小的阵列,这是你可以在栈上做的唯一一件事。


-


- Pete

Roundhouse Consulting,Ltd。( www.versatilecoding.com

标准C ++库扩展:一个教程和

参考的作者。 ; ( www.petebecker.com/tr1book


这篇关于搜索基于堆栈的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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