I'm making a small virtual machine; in my virtual machine I read instructions from a binary file. Each instruction is 1 byte in size. When the VM starts, it loads the binary file into a vector. Then I use a switch and a for loop to execute the instructions.
But here's where my question starts. I have a vector called "Stack"; it's my virtual machines stack for the program that's running. The problem is I want to store different kinds of data in the vector (Signed and Unsigned Integers, Strings, etc ...).
To do this I created my own object (robj) and made the vector of type "robj". This lets me store the kind of data I want, but my question is: is this wasteful?
Here's the implementation of my object:
class robj {
public:
int signed_int = 0;
unsigned int unsigned_int = 0;
};
As you can see, my object is really small at the moment, but it will get larger as I add things like strings. The part that I think is wasteful is that, if I store a signed integer on the stack I also have to store an unsigned one because the object defines both types of integers. And this problem will only get worse as I make the object bigger.
So I'd just like to know, is there a less wasteful way to do this?