Skip to content

fix: Don't allocate extraneous memory in FastBufferReader #2265

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

Merged
merged 3 commits into from
Oct 19, 2022

Conversation

simon-lemay-unity
Copy link
Contributor

Creating a FastBufferReader with copyAllocator set to Allocator.None means not to allocate a copy of the buffer, and to instead directly use the one provided by the user. But in that situation the code would still allocate memory for the entire buffer. That memory would go unused.

Props to user Frolo on Discord for finding this issue.

Changelog

  • Fixed: Creating a FastBufferReader with Allocator.None will not result in extra memory being allocated for the buffer (since it's owned externally in that scenario).

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary.

@simon-lemay-unity simon-lemay-unity requested a review from a team as a code owner October 19, 2022 03:39
@@ -65,7 +65,7 @@ internal unsafe void CommitBitwiseReads(int amount)
ReaderHandle* readerHandle = null;
if (copyAllocator == Allocator.None)
{
readerHandle = (ReaderHandle*)UnsafeUtility.Malloc(sizeof(ReaderHandle) + length, UnsafeUtility.AlignOf<byte>(), internalAllocator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof! Good catch!

@simon-lemay-unity simon-lemay-unity enabled auto-merge (squash) October 19, 2022 19:02
@simon-lemay-unity simon-lemay-unity merged commit 443769e into develop Oct 19, 2022
@simon-lemay-unity simon-lemay-unity deleted the fix/allocator-none-allocation branch October 19, 2022 19:52
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…nologies#2265)

* fix: Don't allocate extraneous memory in FastBufferReader

* Add PR number to CHANGELOG entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants