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);
        }
Ejemplo n.º 2
0
 public IntPtr AddObject(Uri uri)
 {
     if (uri != null)
     {
         var pin = PinBlittable.Create(uri);
         this.Add(pin);
         return(pin.AddrOfPinnedObject());
     }
     else
     {
         return(IntPtr.Zero);
     }
 }
Ejemplo n.º 3
0
 public IntPtr AddBlittable(object item)
 {
     if (item != null)
     {
         var pin = new PinBlittable(item);
         this.Add(pin);
         return(pin.AddrOfPinnedObject());
     }
     else
     {
         return(IntPtr.Zero);
     }
 }