virtual machine memory storage type

Started by
5 comments, last by Zotoaster 13 years, 6 months ago
hey guys,


i got stuck while determining the storage type of my virtual ram. i thought that using a vector(c++) might do the work, but i dont really know how to store ints and floats and strings in it.
one solution would be a vector of pointers, pointing to either int,float or string, could that work?
wouldnt it be better, in terms of performance, to store either the pointer to a string or every ascii value?

greetings!
Advertisement
Why not have three (or however many) separate vectors/containers instead of trying to jam everything into one?
How about using a "vector<boost::any>"?

boost::any is a type which can store either ints/strings/objects etc.



If only basic "core types" are allowed, then I agree with m_switch.
Quote:Original post by Katie
boost::any is a type which can store either ints/strings/objects etc.
A thing isn't quite clear to me: how can I trick it in containing arbitrary runtime-defined types in a useful way.

Previously "Krohm"

thx guys :)
i chose the multi vector implementation since my opcodes tell the vm on which vector to operate on..quite a simply and yet memory saving solution..
boost::any would be another good solution but its too much memory that gets wasted, because of the additional typeinfo which is saved with every vector entry(correct if me.wrong()?)

Quote:Original post by Krohm
If only basic "core types" are allowed, then I agree with m_switch.
Quote:Original post by Katie
boost::any is a type which can store either ints/strings/objects etc.
A thing isn't quite clear to me: how can I trick it in containing arbitrary runtime-defined types in a useful way.




the only solution to store arbitrary types is to define a list of pointers to these objects
or
a list of super classes which holds on the one hand the typeinfo and on the other the pointer.

imho thats the way boost::any does it.
Could you please elaborate? What type should those pointers be? If they are of type boost::any, how do this takes us closer to the goal?
I don't quite get it.

While I can see the management benefit of degenerating everything to a list of fields, I'm not 100% sure this would be a good idea. It seems to me that casts would be needed anyway sooner or later.

Previously "Krohm"

Make a union of all the basic types your ram can store, and then simply have a buffer of those.

I.e.

union Value{    char Byte;    int Int;    double Double;};std::vector<Value> _mem;

This topic is closed to new replies.

Advertisement