Am I wasting memory with this? Alternatives?

Hello everyone,

I was just wondering if what I’ll try to explain is an innecesary waste of memory or is actually fine.

Let’s say I have a class (we’ll call it Information), which holds quite a lot of data (not that much, a couple of float values, a texture2D, strings…), and I want to add a pair of values int/Information, to a queue. Of course I can’t do that, as the generic queue only accepts for one type to be added, so I was thinking on creating a new class Information_with_int, which containt an instance of the class Informtion, and an integer, then passing that new data type to the method.

So I was wondering, am I increasing the memory cost (i mean greatly) by doing this? When I create an instance for the new class will I waste the whole memory an Information instance takes? (plus the memory an integer takes which is quite neglectable at this point). Or as it’s all done by references, it will only waste the little bit of memory is needed to hold those pointers?

I don’t know many things which happen at low level so the only thing left is asking (and of course, search the web, but something like this isn’t generating many valid search results, it will take a lot of time studying to figure out some basic doubt).

Thank you very much!

Your new class would just take the memory for a reference to the instance (4 bytes) plus an int (4 bytes). You might consider using a struct as it won’t then need garbage collecting when you are done with the instance in the queue.