But you can't have arbitrary large without some reference to all the kinds of data you might have.
If you start with this
Code:
struct data
{
double x;
double y;
double z;
} data;
char scratch[32];
data inst;
memcpy(&scratch, &inst, sizeof(data));
That's all well and good.
But if you change things and forget the hidden dependency, you're screwed.
Code:
struct data
{
double x[2];
double y[2];
double z[2];
} data;
char scratch[32]; // oops, this isn't big enough any more
data inst;
memcpy(&scratch, &inst, sizeof(data));
Sure, you can do this, which make sure scratch follows the size of data.
Code:
struct data
{
double x;
double y;
double z;
} data;
char scratch[sizeof(data)];
data inst;
memcpy(&scratch, &inst, sizeof(data));
But that's just a complete hack over the much simpler.
Code:
struct data
{
double x;
double y;
double z;
} data;
data scratch;
data inst;
scratch = inst;
I'm guessing you have many 'data' that you're not telling us about.
Consider
Code:
struct data
{
double x;
double y;
double z;
} data;
struct data2 ....
struct data3 ....
etc
// A union of all the possible things in your scratch will be
// big enough to store any of them.
union {
unsigned char any[1];
data d0;
data1 d1;
data2 d2;
} scratch;
data inst;
// do either of these
scratch.d0 = inst;
memcpy(scratch.any,&inst,sizeof(inst));