Jump to content
  • Advertisement
Sign in to follow this  
xSKOTTIEx

writing to void pointers

This topic is 4508 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
Advertisement
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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!