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.
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.