unsafe private NativeRuntime.IFabricOperationData CreateNativeOperationData(IOperationData data, uint[] sizes)
        {
            NativeRuntime.IFabricOperationData operationData = null;
            using (var pin = new PinBlittable(sizes))
            {
                operationData = this.operationDataFactory.CreateOperationData(pin.AddrOfPinnedObject(), (uint)sizes.Length);
            }

            // get a pointer to the memory that native code allocated in the operation data it created for us
            uint   countAllocatedByNative;
            IntPtr nativeBuffersRaw = operationData.GetData(out countAllocatedByNative);

            ReleaseAssert.AssertIfNot(countAllocatedByNative == (uint)sizes.Length, StringResources.Error_BufferNumberMismatach);
            NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffers = (NativeTypes.FABRIC_OPERATION_DATA_BUFFER *)nativeBuffersRaw;

            // copy the data into the buffers allocated by native
            int index = 0;

            foreach (var item in data)
            {
                NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffer = nativeBuffers + index;
                ReleaseAssert.AssertIfNot(nativeBuffer->BufferSize == sizes[index], string.Format(CultureInfo.CurrentCulture, StringResources.Error_BufferAllocationSizeMismatch_Formatted, index, nativeBuffer->BufferSize, sizes[index]));

                Marshal.Copy(item.Array, item.Offset, nativeBuffer->Buffer, item.Count);
                index++;
            }

            return(operationData);
        }
예제 #2
0
        internal static OperationData CreateFromNative(NativeRuntime.IFabricOperationData operationData)
        {
            // null operationData is already handled by the caller.
            Requires.Argument("operationData", operationData).NotNull();

            uint   count;
            IntPtr buffer = operationData.GetData(out count);

            return(OperationData.CreateFromNative(count, buffer));
        }