Sign in to follow this  

passing and retrieving data from a buffer

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

here is an example of what I'm trying to do : //// class called Data Data::Data() { char *pcPacket = new char; } void Data::setPacketData( const char* pcPacketData ) { *pcPacket = *pcPacketData; } void Data::getPacketData( const char* pcPacketData ) { *pcPacketData = *pcPacket; } int main { stucture vector3 { int x,y, z; }; Data C_Data; vector3 vec3; /// this would work C_Data.setPacketData( (char*)&vec3 ); /// this would not work, the returned data would not change? C_Data.getPacketData( (char*)&vec3 ); return 0; } so the vec3 that's sent into the getPacketData function wont change because what im trying to change/cast is structure. If know this would work if i was using floats or integers but not for classes or structs. is there a way to do it? when i allocate the pcPacket, i should put it into an array, depending on the size of the structure that was sent right? then it would perhaps work? [Edited by - themadme on November 18, 2008 6:14:29 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by themadme
so the vec3 that's sent into the getPacketData function wont change because what im trying to change/cast is structure.

If know this would work if i was using floats or integers but not for classes or structs.

is there a way to do it?
That code only copies 1 byte into the buffer, so you'll get part of the X component of the vector stored. Assuming that's just a typo and you'd be specifying the buffer size somehow, your code would work fine - getPacketData() would update the data at the pointer passed, which would update the vec3 struct in main().

Share this post


Link to post
Share on other sites

This topic is 3313 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this