I can’t find anything on the net that tells how to put a data type into a pre-allocated block of memory. I hate doing memory management myself, but in this case I must.
I have a block of memory that is 10 bytes long. (My app is 64bit using Visual C.) What I want to be able to do is put 1 unsigned int into bytes 0-3, a char into [4] and char into [5], and another unsigned int into [6-9].
I tried ssprintf already.
So I’m trying to figure out a way to 1) store it into this block of memory and 2) retrieve it.
IMO, a good way to accomplish that is by defining a struct containing the data you described:
Then you can simply fill in your data:
Note the
#pragma pack(1)directive tells the compiler to use a 1-byte alignment. If you don’t know what it means, you can read about data structure alignment.