std :: deque内存使用 [英] std::deque memory use

查看:549
本文介绍了std :: deque内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个简单的统计引擎,使用deque返回滚动平均值和方差来提供数据队列。

I have implemented a simple statistical engine to return rolling mean and variance using a deque to provide a data queue.

deque由多个条目构成,等于滚动数值。

The deque is constructed with a number of entries equal to the rolling number of values.

值到达最旧的值被弹出的前面和新的推到后面。

When a new value arrives the oldest value is popped of the front and the new one pushed onto the back.

我需要确保这不会增长在内存中,因为它预计作为一个后台任务运行很长时间。

I need to be sure that this is not going to grow in memory as it is expected to run as a background task for a long time.

deque是否在使用的堆上分配?

Does deque allocate on the heap in use? Are there flags that I can use to fix its size?

我在RHEL 5.3上使用G ++ 4.1.2

I am using G++ 4.1.2 on RHEL 5.3

推荐答案

基本上,任何动态大小的容器都会从堆中分配内存。另一个问题提供了概述deque

但在特定情况下,队列总是具有相同的大小。如果您遇到了deque的问题,可以使用循环缓冲区实现一个简单的固定大小的队列固定大小的数组。这个实现应该从根本上更好的内存行为(因为它从来不需要重新分配)。无论其优点是值得实施的麻烦,很难评估没有剖析数据。

But in your particular case, the queue always has the same size. If you hit problems with the deque, it might be beneficial to implement a simple fixed-size queue using a circular buffer on a fixed-sized array. This implementation should have fundamentally better memory behaviour (since it never requires reallocation). Whether its advantage is worth the trouble of implementing is hard to assess without profiling data.

这篇关于std :: deque内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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