Sign in to follow this  

writing to void pointers

This topic is 4328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Yes. But I think rip-off is saying to use char* instead of void* right from the start.

Share this post


Link to post
Share on other sites
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*

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this