Is there a safe / standard way to manage unstructured memory in C++?
- by andand
I'm building a toy VM that requires a block of memory for storing and accessing data elements of different types and of different sizes. I've done this by writing a wrapper class around a uint8_t[] data block of the needed size. That class has some template methods to write / read typed data elements to / from arbitrary locations in the memory block, both of which check to make certain the bounds aren't violated. These methods use memmove in what I hope is a more or less safe manner. That said, while I am willing to press on in this direction, I've got to believe that other with more expertise have been here before and might be willing to share their wisdom. In particular:
1) Is there a class in one of the C++ standards (past, present, future) that has been defined to perform a function similar to what I have outlined above?
2) If not, is there a (preferably free as in beer) library out there that does?
3) Short of that, besides bounds checking and the inevitable issue of writing one type to a memory location and reading a different from that location, are there other issues I should be aware of?
Thanks.-&&