writing to void pointers

Started by
5 comments, last by SirKnight 18 years, 1 month ago
I'm trying to do some binary input and output on a file for game databasing, and I'm using a buffer pool to prevent reading times for information that may already be in memory. But because the information in the file can vary depending on where it is, I've opted for void* as the transfer from the buffer pool to the client. Basically: given a void*, how do I copy binary information into it? Thanks in advance!
---------Coming soon! Microcosm II.
Advertisement
Use char *, because a char is the same size as one byte.
so a cast could easily be made then?

(char*)space
---------Coming soon! Microcosm II.
Yes. But I think rip-off is saying to use char* instead of void* right from the start.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
but what if the bytes lay down into a structure, like a structure of ints?

i could do this

IntStruct* struct = new IntStruct();
get( struct );

where the parm is a void*
---------Coming soon! Microcosm II.
Before you write, you need to cast back to the original type.

So in your structure example:

void get( void *p )
{
IntStruct *is = (IntStruct*)p;
copy( is, data );
}



-SirKnight
Of course you could always cast to char* and copy byte-by-byte. It wouldn't matter if you're using a structure or not.


-SirKnight

This topic is closed to new replies.

Advertisement