My apologies in advance if this is the wrong place for this.
I'm currently in the early stages of developing a game, specifically creating the 'building blocks'. With this game being turn-based, I am concentrating more on memory economy than processor usage. For this and other reasons, I have started working on a 'variable-size variable' to hold values of different sizes. Here is a code fragment that I whipped up on this computer. Since it wasn't my computer, I'm afraid error-checking has been restricted to a quick once-over.
While I'll explain the theory if asked, the main point is this: hold_val is an integer of a size sufficient to hold the value being stored. With, say, 16-bit or 32-bit integers this is no problem, but with 48 or 72-bit values, for example, the predefined integer types won't do. So, I'm asking if someone can tell me how the predefined types are made so I can copy that technique to make my own non-standard sizes.Code:// Conceptual example of dynamically-sized variable. // Assumes single-byte alignment for space efficiency. template <class hold_val> struct var_var { BYTE *ptr[sizeof(hold_var)]; var_var() // Complete version will have more constructors. { for(register int i=0;i<(sizeof(hold_val));i++) { ptr[i] = new BYTE; *ptr[i] = 0; } } ~var_var() { for(register int i=0;i<(sizeof(hold_val));i++) { delete ptr[i]; } } };



LinkBack URL
About LinkBacks



CornedBee