Original Post
I have my game running as a client/server architecture and I am sending data from one to the other. I am now optimizing the data I send over the network and I am currently doing this:
I have a class set up like so:
[source lang="cpp"]class temp
{
int a;
BOOL b;
int c;
foo * d1;
foo2 * d2;
CString eStr;
CString fStr;
};[/source]
And the identical class on both the client and server.
I am sending variables a,b, and c as one struct, and I send the other CString data in their own packets for now.
Initially, I was sending each variable over as a packet, now I am sending data over in structs. I was sending these "base" data types (a,b,c) over as a struct by putting them in their own struct like so:
[source lang="cpp"]class temp
{
struct _baseValues
{
int a;
BOOL b;
int c;
}
foo * d1;
foo2 * d2;
Cstring eStr;
CString fStr;
};[/source]
And sending it over in a char array like so:
[source lang="cpp"]LPTSTR aStr = convStr.GetBufferSetLength(sizeof(temp::_baseValues));
memcpy( (void*)aStr, (char*)pStr, sizeof(temp::_baseValues) );[/source]
However my question is that is it simpler for me to ignore creating another struct for my base values, and just send the data over in the original class setup (the first class in this post ) and copying it over like so:
[source lang="cpp"]LPTSTR aStr = convStr.GetBufferSetLength(12);
memcpy( (void*)aStr, (char*)pStr, 12 );[/source]
and reading it in on the client like this:
[source lang="cpp"]memcpy( (void*)tempObj, (LPCTSTR)packetCharStr, 12 );[/source]
Everything works fine, but my question is, except for the fact I have to enter a manual size for the data sizes for the conversions, could this cause any problems? Aside I have to watch the order of which I place members in the class, and not worry about endian problems from different operating systems, is this acceptable? Or could I have some random memory problems doing this?
I can go back to putting the base values (a,b,c) back into a struct, but this does seem a bit simpler, and I won't have to do a large code overhaul.
Thanks
I have a class set up like so:
[source lang="cpp"]class temp
{
int a;
BOOL b;
int c;
foo * d1;
foo2 * d2;
CString eStr;
CString fStr;
};[/source]
And the identical class on both the client and server.
I am sending variables a,b, and c as one struct, and I send the other CString data in their own packets for now.
Initially, I was sending each variable over as a packet, now I am sending data over in structs. I was sending these "base" data types (a,b,c) over as a struct by putting them in their own struct like so:
[source lang="cpp"]class temp
{
struct _baseValues
{
int a;
BOOL b;
int c;
}
foo * d1;
foo2 * d2;
Cstring eStr;
CString fStr;
};[/source]
And sending it over in a char array like so:
[source lang="cpp"]LPTSTR aStr = convStr.GetBufferSetLength(sizeof(temp::_baseValues));
memcpy( (void*)aStr, (char*)pStr, sizeof(temp::_baseValues) );[/source]
However my question is that is it simpler for me to ignore creating another struct for my base values, and just send the data over in the original class setup (the first class in this post ) and copying it over like so:
[source lang="cpp"]LPTSTR aStr = convStr.GetBufferSetLength(12);
memcpy( (void*)aStr, (char*)pStr, 12 );[/source]
and reading it in on the client like this:
[source lang="cpp"]memcpy( (void*)tempObj, (LPCTSTR)packetCharStr, 12 );[/source]
Everything works fine, but my question is, except for the fact I have to enter a manual size for the data sizes for the conversions, could this cause any problems? Aside I have to watch the order of which I place members in the class, and not worry about endian problems from different operating systems, is this acceptable? Or could I have some random memory problems doing this?
I can go back to putting the base values (a,b,c) back into a struct, but this does seem a bit simpler, and I won't have to do a large code overhaul.
Thanks