gpt4 book ai didi

c# - ArrayPool.Rent(Int32) 方法是线程安全的吗?

转载 作者:太空狗 更新时间:2023-10-29 18:26:20 29 4
gpt4 key购买 nike

我刚刚发现 ArrayPool 的存在,但它的文档有点缺乏。

我想知道 Rent(.)Return(.)是线程安全的。

编辑:看起来我没有注意到文档的“线程安全”部分;但阅读了一些评论和答案后,我松了一口气,我不是唯一没有这样做的人。

最佳答案

更新来自 ta.speot.is 的评论

It literally says on Thread safety This class is thread-safe. All members may be used by multiple threads concurrently

原创

learn.microsoft.com 上没有这样说,但是有一些引用资料表明它是这样的

Add a new System.Buffers namespace to the BCL for Resource Pooling

The Pool will be lightweight and thread-safe, allowing for fast Rent and Return calls from any thread within the process, along with minimal locking overhead, and 0 heap allocations on most Rent calls (exceptions to this will be called out below in the description of the Rent function).

Pooling large arrays with ArrayPool

Recommended: use the ArrayPool.Shared property, which returns a shared pool instance. It’s thread safe and all you need to remember is that it has a default max array length, equal to 2^20 (1024*1024 = 1 048 576).

.

关于c# - ArrayPool<T>.Rent(Int32) 方法是线程安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53273277/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com