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);
        }
Example #2
0
        private static ArraySegment <byte> GetSegment(IntPtr buffer, int index)
        {
            unsafe
            {
                NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffer = (NativeTypes.FABRIC_OPERATION_DATA_BUFFER *)(buffer + (Marshal.SizeOf(typeof(NativeTypes.FABRIC_OPERATION_DATA_BUFFER)) * index));

                return(new ArraySegment <byte>(NativeTypes.FromNativeBytes(nativeBuffer->Buffer, nativeBuffer->BufferSize)));
            }
        }
Example #3
0
        private static unsafe IList <ArraySegment <byte> > CreateFromNativeInternal(uint count, IntPtr buffer)
        {
            List <ArraySegment <byte> > returnValue = new List <ArraySegment <byte> >();

            for (int i = 0; i < count; i++)
            {
                NativeTypes.FABRIC_OPERATION_DATA_BUFFER *nativeBuffer = (NativeTypes.FABRIC_OPERATION_DATA_BUFFER *)(buffer + (Marshal.SizeOf(typeof(NativeTypes.FABRIC_OPERATION_DATA_BUFFER)) * i));
                returnValue.Add(new ArraySegment <byte>(NativeTypes.FromNativeBytes(nativeBuffer->Buffer, nativeBuffer->BufferSize)));
            }

            return(returnValue.AsReadOnly());
        }