-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC-002] Standardize where to return or pass outward by reference #36
Comments
I haven't written any code that does pass out by reference. I think we should return by value as that is easier to understand. And where we do want to pass back values (multiple outputs or allocation avoidance) we should clearly mark the parameter as an out perameter |
I use pass out-by-reference for instances where allocating and copying the necessary data multiple times isn't feasible, or where allocating, passing and then immediately destroying the data would be too heavy on heap allocations. For example, the shader compiler:
This could return a CompilerOutput*, but the lifetime of the object is literally the caller + the line after the caller, and it will never be used again. That's a heavy allocation. Pass out-by-reference allows stack memory of the call site to be used for the allocation, which is better on memory, and doesn't involve a heap allocate and delete, which may even be faster for a hot path like the shader compilation (which is done lazily) |
Yeah that sounds fine to me |
Herein lies the dilemma. We need to be sure between the two of us where the line that makes this okay lies. If it comes down to developer discretion, then that's fair enough - as long as we're on the same page. |
Currently the engine uses a large mixture of the two.
We should standardize where to:
or:
because the current system just doesn't work.
The text was updated successfully, but these errors were encountered: