I have to make a decision which will be very important in future development of my application, so it must be perfect.
The actual question:
For easiness sake it is better to have additional 20 empty bytes, but that seems extremely inefficient. How far is my program affected when I pass a 50 bytes big struct to a function ? =P
And why I am asking:
I run 64bit. That means 8 bytes per variable.
Currently stuff_s is 3*8=24 bytes big.
- Just add three/four more variables, but bloat the struct size and slow down function calling.
- or to choose sometime pretty complicated but safe additional bytes (and RAM space).
I will be using these stuff_ss to contain data objects of any kind in a tree, they can handle an object or module(that is something specific, ignore modules). Data object size can be different… They might even be several Gigabytes to usual structs used. Now I don’t want every damn struct to carry around additional 50 bytes. If that could be only one byte, or not more than 8… =(
I have a struct:
//
// stuff reference (either module or object)
//
struct stuff_s
{
char s; // stuff: 'm' || 'o'
union {
struct {
mfunc_t *fs;
ppackage (*knockf)(ppackage p);
} m;
struct {
void *h;
size_t s;
// HERE should the additional variables go.
} o;
};
};
Use references.
C++:
C:
As to the design of your program, if your data is really, really unknowable, I would recommend using a void * pointer and an object type tag, or derive a class from a base class.
C++:
If you really want I’ll provide a C example but this is getting overly long
EDIT: I saw below that it has to be C compatible. So I’ll expand to include the C equivalent of that last code and also include passing by reference. Keep in mind this is conceptual: it will compile but it isn’t very useful.
C: