-
Notifications
You must be signed in to change notification settings - Fork 610
Description
In a number of places in the storage layer, GC.AllocateArray
is used to allocate an array on the pinned heap, followed shortly by an Array.Clear
. This is redundant, since GC.AllocateArray
pre-initializes the data to zero. I'm guessing this might be a hangover from a previous unmanaged allocator, or from migration from a C/C++ implementation.
If the intent is to use unitialized data in the oversized portion: GC.AllocateUnitializedArray
exists (but only works for blittable types); otherwise and probably simpler to grok (and easier to validate correctness): just remove the Array.Clear
calls, leaving the default/inbuilt zero initialize (i.e. do not switch to GC.AllocateUninitializedArray
).
impact: performance
examples:
BlittableFrame.Allocate
MallocFixedPageSize.InternalAllocate
(2 of)SpanByteAllocator.AllocatePage
similar with simple array creation (no GC alloc):
GenericAllocator<,>.AllocatePage
GenericFrame<,>.Allocate