jtmueller / Collections.Pooled

Fast, low-allocation ports of List, Dictionary, HashSet, Stack, and Queue using ArrayPool and Span.
MIT License
547 stars 48 forks source link

Binary Serialization #20

Closed jtmueller closed 5 years ago

jtmueller commented 5 years ago

Describe the bug This is a reminder to test a likely issue that's not been verified yet: it's likely that when pooled collections are serialized and then deserialized, disposing them causes an exception because the deserialized arrays do not come from the ArrayPool, which throws an error if you return to it an array it didn't create.

Expected behavior Either ArrayPool returns should be in a try/catch block, or deserialization should copy the deserialized array into an ArrayPool array instead of using it directly.

jtmueller commented 5 years ago

It turns out this is not a problem. ArrayPool uses the array length to determine if a returned array is not really from the pool, and serialized arrays are the correct length. ArrayPool accepts these just fine - however, I'll put a try/catch around returns just in case.