Example #1
0
        public static unsafe void InitArray(System.Array srcArray,
                                            System.Array dstArray)
        {
#if !REFERENCE_COUNTING_GC && !DEFERRED_REFERENCE_COUNTING_GC
            Barrier.ArrayCopy(srcArray, 0, dstArray, 0, srcArray.Length);
#else
            fixed(int *srcFieldPtr = &srcArray.field1)
            {
                void *src = srcArray.GetFirstElementAddress(srcFieldPtr);

                fixed(int *dstFieldPtr = &dstArray.field1)
                {
                    void *dst  = dstArray.GetFirstElementAddress(dstFieldPtr);
                    int   size = (srcArray.vtable.arrayElementSize *
                                  srcArray.Length);

#if REFERENCE_COUNTING_GC
                    if (dstArray.vtable.arrayOf ==
                        StructuralType.Reference ||
                        dstArray.vtable.arrayOf ==
                        StructuralType.Struct)
                    {
                        int dstLength =
                            size / dstArray.vtable.arrayElementSize;
                        GCs.ReferenceCountingCollector.
                        IncrementReferentRefCounts(Magic.addressOf(srcArray),
                                                   srcArray.vtable,
                                                   0,
                                                   srcArray.Length);
                        GCs.ReferenceCountingCollector.
                        DecrementReferentRefCounts(Magic.addressOf(dstArray),
                                                   dstArray.vtable,
                                                   0,
                                                   dstLength);
                    }
#elif DEFERRED_REFERENCE_COUNTING_GC
                    if (dstArray.vtable.arrayOf ==
                        StructuralType.Reference ||
                        dstArray.vtable.arrayOf ==
                        StructuralType.Struct)
                    {
                        int dstLength =
                            size / dstArray.vtable.arrayElementSize;
                        GCs.DeferredReferenceCountingCollector.
                        IncrementReferentRefCounts(Magic.addressOf(srcArray),
                                                   srcArray.vtable,
                                                   0,
                                                   srcArray.Length);
                        GCs.DeferredReferenceCountingCollector.
                        DecrementReferentRefCounts(Magic.addressOf(dstArray),
                                                   dstArray.vtable,
                                                   0,
                                                   dstLength);
                    }
#endif // REFERENCE_COUNTING_GC
                    System.IO.__UnmanagedMemoryStream.memcpyimpl
                        ((byte *)src, (byte *)dst, size);
                }
            }
#endif // REFERENCE_COUNTING_GC
        }