let's say we have this struct:
1
2
3
4
5
6
7
8
9
10
11
12 | struct Unit
{
int x;
int y;
void Move(int mov_x, int mov_y)
{
x += mov_x;
y += mov_y;
}
};
|
And this stand alone function:
| void Move(Unit *u, int mov_x, int mov_y)
{
u->x += mov_x;
u->y += mov_y;
}
|
And pretend that we create like 500 units in a game.
If i'm not mistaken this would result in the Unit beeing more memory expensive since every Unit will have the move function instead of just have one stand alone function that moves Units.
Does it make sence?
And what are you thoughts on splitting functions inside/outside structs/classes, what kind of functions would be good to have inside structs and which would be better to have outside.
I got bugged by this thought and would like to here some opinions on this.
cheers :)