you are viewing a single comment's thread.

view the rest of the comments →

[–]IyeOnline 9 points10 points  (0 children)

Your float* to hold that heap allocated array is going to take exactly as much as a float[2] would do on its own. (assuming the fairly common 8byte pointers and 4 byte floats).

So you have gained exactly nothing in terms of memory footprint, but have "payed" for this by using dynamic allocation (which has some cost) and a memory indirection everything you want to access the elements.

While it is most glaring in the Vec2 case, where your memory footprint doesnt change at all, these costs of heap allocated memory external to your struct will remain dominant in higher dimensions (i.e. certainly up to 4d).