Example #1
0
        protected override unsafe void WriteAsync(float* sourcePtr, int sourceBeginIndex, int count, int targetBeginIndex, DataArrayCompletedCallback doneFunc)
        {
            VerifyIsNotConst();

            try
            {
                Marshal.Copy(new IntPtr(sourcePtr + sourceBeginIndex), InternalManagedArray.InternalArray, targetBeginIndex, count);
                doneFunc(null);
            }
            catch (Exception ex)
            {
                doneFunc(ex);
            }
        }
Example #2
0
        public Task Read(int sourceBeginIndex, int count, float[] targetArray, int targetBeginIndex)
        {
            Args.Requires(() => sourceBeginIndex, () => sourceBeginIndex >= 0 && sourceBeginIndex < Size);
            Args.Requires(() => count, () => count > 0 && count <= Size);
            Args.Requires(() => targetArray, () => targetArray != null && targetArray.Length <= Size);
            Args.Requires(() => targetBeginIndex, () => targetBeginIndex >= 0 && targetBeginIndex < targetArray.Length);

            var compl = new TaskCompletionSource<object>();
            var arrayH = new GCHandleRef(GCHandle.Alloc(targetArray, GCHandleType.Pinned));
            var doneH = new GCHandleRef();
            DataArrayCompletedCallback doneFunc = null;
            doneFunc = new DataArrayCompletedCallback(ex =>
            {
                try
                {
                    if (ex == null) compl.SetResult(null); else compl.SetException(ex);
                }
                finally
                {
                    arrayH.Handle.Free();
                    doneH.Handle.Free();
                }
            });
            doneH.Handle = GCHandle.Alloc(doneFunc);
            try
            {
                ReadAsync(sourceBeginIndex, count, (float*)arrayH.Handle.AddrOfPinnedObject(), targetBeginIndex, doneFunc);
                return compl.Task;
            }
            catch
            {
                arrayH.Handle.Free();
                doneH.Handle.Free();
                throw;
            }
        }
Example #3
0
 protected abstract void ReadAsync(int sourceBeginIndex, int count, float* targetPtr, int targetBeginIndex, DataArrayCompletedCallback doneFunc);
Example #4
0
 protected abstract void WriteAsync(float* sourcePtr, int sourceBeginIndex, int count, int targetBeginIndex, DataArrayCompletedCallback doneFunc);