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!
virtual machine memory storage type
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.
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 KatieA thing isn't quite clear to me: how can I trick it in containing arbitrary runtime-defined types in a useful way.
boost::any is a type which can store either ints/strings/objects etc.
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()?)
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.
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 KatieA thing isn't quite clear to me: how can I trick it in containing arbitrary runtime-defined types in a useful way.
boost::any is a type which can store either ints/strings/objects etc.
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.
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.
Make a union of all the basic types your ram can store, and then simply have a buffer of those.
I.e.
I.e.
union Value{ char Byte; int Int; double Double;};std::vector<Value> _mem;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement