Пример #1
0
            // remove the local function when https://github.com/dotnet/runtime/issues/5973 is implemented
            static T[] AllocateNewUninitializedArray(int length, bool pinned)
            {
                GC_ALLOC_FLAGS flags = GC_ALLOC_FLAGS.GC_ALLOC_ZEROING_OPTIONAL;

                if (pinned)
                {
                    flags |= GC_ALLOC_FLAGS.GC_ALLOC_PINNED_OBJECT_HEAP;
                }

                return(Unsafe.As <T[]>(AllocateNewArray(typeof(T[]).TypeHandle.Value, length, flags)));
            }
Пример #2
0
            static T[] AllocateNewUninitializedArray(int length, bool pinned)
            {
                GC_ALLOC_FLAGS flags = GC_ALLOC_FLAGS.GC_ALLOC_ZEROING_OPTIONAL;

                if (pinned)
                {
                    flags |= GC_ALLOC_FLAGS.GC_ALLOC_PINNED_OBJECT_HEAP;
                }

                if (length < 0)
                {
                    throw new OverflowException();
                }

                T[] array = null;
                RuntimeImports.RhAllocateNewArray(EETypePtr.EETypePtrOf <T[]>().RawValue, (uint)length, (uint)flags, Unsafe.AsPointer(ref array));
                if (array == null)
                {
                    throw new OutOfMemoryException();
                }

                return(array);
            }
Пример #3
0
 internal static extern Array AllocateNewArray(IntPtr typeHandle, int length, GC_ALLOC_FLAGS flags);