コード例 #1
0
ファイル: QtRecord.cs プロジェクト: Albeoris/Septerra
        public static Boolean Find(UInt32 qtRecordId, out Byte *filePath, out UInt32 offset)
        {
            offset = 0;

            DbRecordId dbRecordId = new DbRecordId(qtRecordId);

            if (_pinnedNames.TryGetValue(dbRecordId, out SafeGCHandle ptr))
            {
                filePath = (Byte *)ptr.AddrOfPinnedObject();
                return(true);
            }

            if (Indices.TryGetResourcePath(dbRecordId, out String resourcePath))
            {
                Int32  arraySize = Encoding.ASCII.GetByteCount(resourcePath) + 1; // \0
                Byte[] array     = new Byte[arraySize];
                Encoding.ASCII.GetBytes(resourcePath, 0, resourcePath.Length, array, 0);

                SafeGCHandle handle = new SafeGCHandle(array, GCHandleType.Pinned);
                _pinnedNames[dbRecordId] = handle;

                filePath = (Byte *)handle.AddrOfPinnedObject();
                return(true);
            }

            filePath = null;
            return(false);
        }
コード例 #2
0
ファイル: CaFileReader.cs プロジェクト: rebootus/Esthar
        public override void Open()
        {
            Close();

            if (IOStream.Length % 40 == 0)
            {
                Rects = IOStream.ReadStructsByTotalSize <CaCamera>(IOStream.Length);
            }
            else if (IOStream.Length % 38 == 0)
            {
                long count = IOStream.Length / 38;
                Rects = new CaCamera[count];

                byte[] buff = new byte[40];
                using (SafeGCHandle handle = new SafeGCHandle(buff, GCHandleType.Pinned))
                    for (int i = 0; i < count; i++)
                    {
                        IOStream.EnsureRead(buff, 0, 38);
                        Rects[i] = (CaCamera)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), TypeCache <CaCamera> .Type);
                    }
            }
            else
            {
                throw new Exception("Неизвестный тип камеры.");
            }
        }
コード例 #3
0
        private void InitRow(int row)
        {
            ISurface <TPixel> source = this.source as ISurface <TPixel>;

            if (source != null)
            {
                this.rowPtrs[row] = source.GetRowPointer <TPixel>(row);
            }
            else
            {
                if (this.freeRow == null)
                {
                    this.rows[row] = new TPixel[this.width];
                    this.freeRowMissCount++;
                }
                else
                {
                    this.rows[row] = this.freeRow;
                    this.freeRow   = null;
                    this.freeRowHitCount++;
                }
                this.pinnedRows[row] = SafeGCHandle.Alloc <TPixel[]>(this.rows[row], GCHandleType.Pinned);
                this.rowPtrs[row]    = this.pinnedRows[row].AddrOfPinnedObject();
                SharedSurface <TPixel> dst = new SharedSurface <TPixel>(this.rowPtrs[row], this.width, 1, this.width * RendererRowCache <TPixel> .sizeOfTPixel);
                this.source.Render(dst, new PointInt32(0, row));
                this.rowRenderCounts[row]++;
                this.currentRowCount++;
                this.maxRowCount = Math.Max(this.currentRowCount, this.maxRowCount);
            }
        }
コード例 #4
0
ファイル: DdsHeaderDecoder.cs プロジェクト: pinguallyj/Pulse
 public static DdsHeader FromFileStream(Stream input)
 {
     byte[] buff = new byte[128];
     using (SafeGCHandle handle = new SafeGCHandle(buff, GCHandleType.Pinned))
     {
         input.EnsureRead(buff, 0, buff.Length);
         return((DdsHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject() + 4, TypeCache <DdsHeader> .Type));
     }
 }
コード例 #5
0
        public unsafe FastUncheckedRectInt32ArrayWrapper(UnsafeList <RectInt32> list, int startIndex, int length)
        {
            RectInt32[] numArray;
            int         num;

            list.GetArray(out numArray, out num);
            this.arrayGCHandle = SafeGCHandle.Alloc <RectInt32[]>(numArray, GCHandleType.Pinned);
            this.pArray        = (RectInt32 *)((((IntPtr)startIndex) * sizeof(RectInt32)) + ((void *)this.arrayGCHandle.AddrOfPinnedObject()));
            this.count         = length;
        }
コード例 #6
0
ファイル: DdsHeaderEncoder.cs プロジェクト: pinguallyj/Pulse
        public static void ToFileStream(DdsHeader header, Stream output)
        {
            byte[] buff = new byte[128];
            using (SafeGCHandle handle = new SafeGCHandle(buff, GCHandleType.Pinned))
            {
                IntPtr ptr = handle.AddrOfPinnedObject();

                Marshal.WriteInt32(ptr, DdsHeader.MagicHeader);
                Marshal.StructureToPtr(header, ptr + 4, false);

                output.Write(buff, 0, buff.Length);
            }
        }
コード例 #7
0
        public static unsafe IDisposable ChangeArrayType(Array array, Int32 oldElementSize, out void *pointer)
        {
            if (array.Length < 1)
            {
                throw new NotSupportedException();
            }

            SafeGCHandle handle = new SafeGCHandle(array, GCHandleType.Pinned);

            try
            {
                pointer = handle.AddrOfPinnedObject().ToPointer();
                UIntPtr *arrayPointer = (UIntPtr *)pointer;
                UIntPtr  arrayLength  = *(arrayPointer - 1);
                UIntPtr  arrayType    = *(arrayPointer - 2);
                UInt64   arraySize    = ((UInt64)arrayLength * (UInt64)oldElementSize);

                if (arraySize % (UInt64)UnsafeSize != 0)
                {
                    throw new InvalidCastException();
                }

                try
                {
                    *(arrayPointer - 1) = new UIntPtr(arraySize / (UInt64)UnsafeSize);
                    *(arrayPointer - 2) = ArrayTypePointer;

                    return(new DisposableAction(() =>
                    {
                        *(arrayPointer - 1) = arrayLength;
                        *(arrayPointer - 2) = arrayType;

                        // ReSharper disable once AccessToDisposedClosure
                        handle.Dispose();
                    }));
                }
                catch
                {
                    *(arrayPointer - 1) = arrayLength;
                    *(arrayPointer - 2) = arrayType;
                    throw;
                }
            }
            catch
            {
                handle.Dispose();
                throw;
            }
        }
コード例 #8
0
 public unsafe FastUncheckedRectInt32ArrayWrapper(RectInt32[] array, int startIndex, int length)
 {
     this.arrayGCHandle = SafeGCHandle.Alloc <RectInt32[]>(array, GCHandleType.Pinned);
     this.pArray        = (RectInt32 *)((((IntPtr)startIndex) * sizeof(RectInt32)) + ((void *)this.arrayGCHandle.AddrOfPinnedObject()));
     this.count         = length;
 }
コード例 #9
0
ファイル: WeakReference.cs プロジェクト: erchiguire/Fuxion
 /// <summary>
 /// Initializes a new instance of the <see cref="WeakReference{T}"/> class, referencing the specified object.
 /// </summary>
 /// <param name="target">The object to track. May not be null.</param>
 public WeakReference(T target)
 {
     this.safeHandle = new SafeGCHandle(target, GCHandleType.Weak);
 }
コード例 #10
0
 private static unsafe UIntPtr GetArrayTypePointer()
 {
     T[] result = new T[1];
     using (SafeGCHandle handle = new SafeGCHandle(result, GCHandleType.Pinned))
         return(*(((UIntPtr *)handle.AddrOfPinnedObject().ToPointer()) - 2));
 }