Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

pointer help :D

This topic is 3059 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

DWORD X = 5; // X = 5 ; DWORD * Y = &X ; // Y = address of X DWORD copy = *Y ; // copy is now = 5 , dereferenced Y byte bytecopy = *(byte*)Y ; // point to the address of Y but only copy 8 bits instead of 4 bytes and get the value those 8 bits produce and store it in bytecopy? am i understanding the last statement correctly? byte bytecopy = *(byte*)Y ; // point to the address of Y but only copy 8 bits instead of 4 bytes and get the value those 8 bits produce and store it in bytecopy? c

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Well for instance in the following case. I have a serialization system in C++. At the lowest level when writing something to disk (whether string type, char * long etc. etc) it will write it as a sequence of bytes. So at the lowest level I do actually write every individual byte (okay I use it as a character buffer but the principal stays the same ).

stream.write( (char*)Buffer, sizeof( Type ) );

Now type can be any integer type (string needs some specialization, i.e. a separate function since it needs to store length and the character buffer in string).

So any data will eventually end up as a stream of characters.

However in my code I rarely dereference a single byte from a larger datatype. The above is one example, other examples might be working with colors where you have an ARGB layout and you need to convert to another layout like RGBA.

[Edited by - Ron AF Greve on February 7, 2010 9:30:45 AM]

Share this post


Link to post
Share on other sites
You would need something like this if you need to serialize some object data into a byte stream for transfering across some external interface.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!