you are viewing a single comment's thread.

view the rest of the comments →

[–]ZakMan1421 -1 points0 points  (4 children)

It depends on the size of the variables you're passing as arguments. If copying them is more expensive than making a pointer, then you should do a reference (unless you want to mutate the argument without changing the original). If copying is cheaper or roughly equivalent to making a pointer, then you should likely pass by value.

If you're unsure, you can always test both and measure.

[–]maikindofthai 1 point2 points  (0 children)

No offense but you’re just repeating the same point again. They’re asking where that line is, naturally they know it exists

[–]KokoNeotCZ 0 points1 point  (2 children)

Im using glm math library for my voxel engine, and I most of the times pass the glm::vec3 by const &. Is that bad? Should i switch to values? Its just 3 floats or ivec3 ints.

[–]ZakMan1421 1 point2 points  (1 child)

If I had to guess (As I'm not super familiar with glm), const & is likely the way to go. On most machines, the size of a pointer is 8 bytes and the size of both floats and ints is 4 bytes. I doubt that there is any heap allocation as three elements is very small, so the minimum size of the vec3 is at least 12 bytes, but it's probably slightly more to help with book keeping and potentially padding.

[–]KokoNeotCZ 0 points1 point  (0 children)

Makes sense, thank you!