如何在C ++中创建循环队列 [英] How to Create a Circular Queue in C++

查看:56
本文介绍了如何在C ++中创建循环队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计


我想创建一个循环队列,用于使用GNU C ++在

QNX上进行高速数据采集。

是否有人知道使用STL或任何其他

方式的有效方法。

我使用queue或dqueue来实现它...

任何好的信息都表示赞赏。我希望它能够高效,高速地用于开发设备驱动程序。


谢谢

subra

Hi Folks

I want to create a circular queue for high speed data acquistion on
QNX with GNU C++ .
Does any one know of efficient ways either Using STL or in any other
way .
I am thing of using queue or dqueue to implement it ...
any good info is appreciated . I want it to be efficient , high speed
for developing device drivers .

Thanks
subra

推荐答案

您将在队列中存储哪种类型的数据?对于至少
的开销量,为什么不制作一个所述类型的数组,并且计数

数字增加到一定数量,然后设置为0

再次......基本上是数组中的循环缓冲区。除非你需要一个

的开始和结束计数器......确保它们不会交叉。


此外,还有一个队列类:< a rel =nofollowhref =http://www.cppreference.com/cppqueue/target =_ blank> http://www.cppreference.com/cppqueue/


现在我想到了,我不知道你的意思是什么?

队列...循环缓冲区?我正在失去它。

What type of data will you be storing in the queue? For the least
amount of overhead, why not make an array of said type, and a counting
number that is incremented until a certain number, then set to 0
again...basically a circular buffer in an array. Unless you need a
start and end counter...make sure that they don''t cross.

Also, there is a queue class: http://www.cppreference.com/cppqueue/

Now that I think of it, I don''t know what you mean by circular
queue...circular buffer? I''m losing it.


2006年1月10日10:35:37 -0800, av *** @ mailcity.com 写道:
On 10 Jan 2006 10:35:37 -0800, av***@mailcity.com wrote:
我想创建一个循环队列,用于使用GNU C ++在QNX上进行高速数据采集。有没有人知道使用
STL或以任何其他方式有效的方式。
我是使用队列或队列来实现它...
任何好的信息是值得赞赏的。我希望它能够高效,高速地开发设备驱动程序。
I want to create a circular queue for high speed data acquistion on
QNX with GNU C++ . Does any one know of efficient ways either Using
STL or in any other way .
I am thing of using queue or dqueue to implement it ...
any good info is appreciated . I want it to be efficient , high speed
for developing device drivers .




在这里输入''循环队列'': http://www.koders.com/

祝福,

Roland Pibinger



Enter ''circular queue'' here: http://www.koders.com/

Best wishes,
Roland Pibinger


除非您确定可以预测所有
分配/否则不要使用STL队列准确地解除分配。你最好自己制作一个保证分配器(非)使用的循环队列,或者找一个专门为设备驱动程序设计的
。另外一些(很容易避免
)STL容器函数会抛出异常,这些异常应该永远不会在设备驱动程序中使用(除非你有一个魔术编译器

创建易于预测的抛出/捕获行为)。


同样,关键点是确保您对任何

无界操作具有完全控制权(通常是分配/解除分配),如果你能够以这种方式找到一种方法来使用STL容器,那就去吧。


Jeremy Jurksztowicz

Do not use STL queue''s unless you are sure you can predict all
allocations/deallocations precisely. It is best you make your own
circular queue that has guaranteed allocator (non) usage, or find one
specifically made for device drivers. Additionally some (easily
avoided) STL container functions throw exceptions, which should never
be used in a device-driver (unless you have a magic compiler which
creates easily predictable throw/catch behavior).

Again, the key point is to make sure you have COMPLETE control over any
unbounded operations (most often allocations/deallocations), if you can
find a way to use an STL container in such a way, go for it.

Jeremy Jurksztowicz


这篇关于如何在C ++中创建循环队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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