Skip to content
Discussion options

You must be logged in to vote

The main benefit of using MemoryMarshal.CreateFromPinnedArray is to skip the GC handle allocation when calling Memory<T>.Pin. However, WebSocket (as well as most I/O routines) prefer to extract the underlying array directly and doesn't use that path.

In my opinion, it should be faster since there is dedicated pinned heap.

It's dual blade. It can avoid occupying Gen 0 memory area if pinned for longer time, but also reduce memory locality for using separated heap.

Plus GC will skip all together inspecting such array?

It will be collected as usual. The only difference of pinned heap is no moving during GC collection.

What are the trade-offs of keeping WebSocket buffers pinned? I see onl…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@stephentoub
Comment options

@unsafePtr
Comment options

@huoyaoyuan
Comment options

Answer selected by unsafePtr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants