-
-
Notifications
You must be signed in to change notification settings - Fork 754
Closed
Description
What is safe way to use the SerializeUnsafe?
Is for example following absolutely safe thing to do even in multithreaded scenario:
var unsafeBuffer = MessagePackSerializer.SerializeUnsafe(foo);
// simulate some work done on this same thread.
//some other thread may use the MessagePackSerializer while this is going on.
// is it safe to use unsafeBuffer later in this same thread?
System.Threading.Thread.Sleep(1000);
var safeBuffer = ArrayPool<byte>.Shared.Rent(unsafeBuffer.Count);
try
{
unsafeBuffer.CopyTo(safeBuffer);
// use the safe buffer...
}
finally
{
// after safe buffer is no more needed return it to pool
ArrayPool<byte>.Shared.Return(safeBuffer);
}
My motivation is to avoid allocating new buffers all the time and instead use pooled buffers.
Metadata
Metadata
Assignees
Labels
No labels