Skip to content

feat: Allow passing an allocator for FastBufferReader's internal handle when using Allocator.None [MTT-3534]#1966

Merged
0xFA11 merged 7 commits intodevelopfrom
feature/readerutilityfunction
Jun 9, 2022
Merged

feat: Allow passing an allocator for FastBufferReader's internal handle when using Allocator.None [MTT-3534]#1966
0xFA11 merged 7 commits intodevelopfrom
feature/readerutilityfunction

Conversation

@Cosmin-B
Copy link
Copy Markdown
Contributor

The change within this PR is required to allow users to create FastBuffer Reader and Writers pools, as before the FastBufferReader's internal handle was always allocated via a Temp allocator, with this change a user can pass in a Persistent allocator.

Changelog

  • Changed: Added a new parameter to the FastBufferReader construct to allow passing a specific Allocator type for allocating a new Buffer Handle, other than a temporary one.

Testing and Documentation

  • This should be covered by previous tests

@Cosmin-B Cosmin-B requested a review from a team as a code owner May 13, 2022 16:27
Copy link
Copy Markdown
Collaborator

@ShadauxCat ShadauxCat left a comment

Choose a reason for hiding this comment

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

Would like to have a more descriptive title for this PR, like "Allow passing an allocator for FastBufferReader's internal handle when using Allocator.None"... it's a little more wordy but expresses why the change is being made, which I think is more important to express than what the change is in the commit summary.

Otherwise good.

@Cosmin-B Cosmin-B changed the title feat: Adding a new parameter to FastBufferReader constructor [MTT-3534] feat: Allow passing an allocator for FastBufferReader's internal handle when using Allocator.None [MTT-3534] May 13, 2022
@Cosmin-B
Copy link
Copy Markdown
Contributor Author

Thanks, @ShadauxCat! And done! Wording things is hard!

}

private static unsafe ReaderHandle* CreateHandle(byte* buffer, int length, int offset, Allocator allocator)
private static unsafe ReaderHandle* CreateHandle(byte* buffer, int length, int offset, Allocator allocator, Allocator handleAllocator)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so now we have Allocator allocator and adding Allocator handleAllocator. what's going on? can't someone just specify allocator = bla instead of allocator = none, handleAllocator = bla?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When passing allocator = Allocator.None, it uses the buffer you pass in directly without any copies, but it still has to make an allocation for the metadata (position, length, etc). Before this change, that always used Allocator.Temp, but that doesn't work if you want to reference an existing buffer and keep the reader around for any length of time at all (it automatically deallocates when the stack context is left), so this change is to allow a buffer to be referenced without copying, while allocating the handle using Allocator.Persistent so it can last longer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotcha, perhaps better parameter names and xmldoc then? :)

Cosmin-B added 3 commits May 20, 2022 11:05
…internalAllocator and the copyAllocator is set to none, we want to make sure we are disposing the handle with the right label
@0xFA11 0xFA11 enabled auto-merge (squash) June 9, 2022 08:07
@0xFA11 0xFA11 merged commit a0b6aa1 into develop Jun 9, 2022
@0xFA11 0xFA11 deleted the feature/readerutilityfunction branch June 9, 2022 10:13
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.

4 participants