Queue memory inefficiency

Hi,

I'm trying to implement a program that uses a queue. Unfortunately, this queue seems to grow in size rapidly, which goes over 2GB of memory, which is more than I can spare.

In fact, I need to store thousand of elements in a queue for further processing. The same element is now semi-randomly put in the queue multiple times, but it is used only once (ignored for all future occurences). So I'm using way more memory than necessary because I'm storing a lot of useless duplicate values (which I don't know are useless when I store them).

I'm considering using a Set instead because this guarantees uniqueness. But isn't that way more CPU intensive? I want to optimize in CPU rather than memory, but it needs to be at least memory acceptable.

Any advice?



I'm considering a queue of pointers that gets its entries checked. I don't get the syntax of that however. I need something like:

queue<*Structure> q;

He doesn't accept this syntax...

EDIT: queue<Structure*> q;
doesn't work either
Last edited on
You should start by calculating exactly how much memory is wasted by duplicates. Then you can determine whether it's worthwhile to remove them.
I guess it is worthwhile. About 6 duplicates for each element are expected overall...

My fix would be to save in the Structure also a boolean value whether the Structure has already been checked. So my "uniqueness"-check doesn't cost that much.

The problem is that to reduce memory I want to use pointers (instead of copying each value into the queue). But queue<Structure*> q; doesn't compile.
Solved: Include file for queue wasn't in .h
Topic archived. No new replies allowed.