Re: loop a queue
On Feb 2, 2:22 am, "Jung, William" <aopiyy...@yahoo.com> wrote:
On Mon, 02 Feb 2009 02:16:29 +0100, "Thomas J. Gritzan"
<phygon_antis...@gmx.de> wrote:
===========
typedef const char* id_type;
typedef unsigned int timestamp_type;
typedef std::pair<id_type, timestamp_type> entry_type;
std::queue< entry_type > * IDs;
[...]
I hope you allocated memory for the queue. But why do you
still use pointers for this?
I have a method in the same Class which will check the queue
and pop any old elements. Do I have to use pointer in this
case?
std::queue< entry_type > * IDs;
-OR-
I can just use static initializatoin
std::queue< entry_type > IDs;
I'm not sure what you mean by "static initialization" here. A
type with a user defined constructor (like std::queue) never has
static initialization, in the sense the expression is used in
the standard.
On the other hand, you can use the object in most places you
could use a pointer to it; the only exception which comes
immediately to mind is in a union.
========================
void Virtual::ProcessMessages()
{
unsigned int current = time (NULL);
while (!IDs->empty())
{
if (current - IDs->front().second > duration)
IDs->pop_front();
else
break;
}
}
Where have you defined the queue? If the lifetime of the queue
is the same as the pointer, the only reason to allocate it
dynamically would be because you didn't know the exact type at
compile time, and that can't really be the case here, because
that only makes sense when the object type supports dynamic
resolution (i.e. has virtual functions). Or because it is a
member of a union, but that seems very unlikely.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34