コード例 #1
0
        internal static unsafe double[] CalculateMovingAvgArray(int[] integerArray, int[] movingWindowArray)
        {
            double[] result = new double[] { };

            MovingAvgInputParam  inputParam  = new MovingAvgInputParam();
            MovingAvgOutputParam outputParam = new MovingAvgOutputParam();

            try
            {
                int arrayLength  = integerArray.Length;
                int windowLength = movingWindowArray.Length;
                inputParam.Size              = arrayLength;
                inputParam.InputArray        = (int *)Marshal.AllocHGlobal(arrayLength * sizeof(int));
                inputParam.Window            = windowLength;
                inputParam.MovingWindowArray = (int *)Marshal.AllocHGlobal(windowLength * sizeof(int));
                intArrayCopy(integerArray, inputParam.InputArray);
                intArrayCopy(movingWindowArray, inputParam.MovingWindowArray);
                outputParam.OutputArray = (double *)Marshal.AllocHGlobal(arrayLength * sizeof(double));

                MovingAvgAPI.MovingAvgStruct(ref inputParam, ref outputParam);

                doublePtrCopy(outputParam.OutputArray, ref result, arrayLength);

                return(result);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (inputParam.InputArray != (int *)IntPtr.Zero)
                {
                    Marshal.FreeHGlobal((IntPtr)inputParam.InputArray);
                    inputParam.InputArray = (int *)IntPtr.Zero;
                }
                if (inputParam.MovingWindowArray != (int *)IntPtr.Zero)
                {
                    Marshal.FreeHGlobal((IntPtr)inputParam.MovingWindowArray);
                    inputParam.MovingWindowArray = (int *)IntPtr.Zero;
                }
                if (outputParam.OutputArray != (double *)IntPtr.Zero)
                {
                    Marshal.FreeHGlobal((IntPtr)outputParam.OutputArray);
                    outputParam.OutputArray = (double *)IntPtr.Zero;
                }
            }
        }
コード例 #2
0
 internal extern static unsafe void MovingAvgStruct(ref MovingAvgInputParam APIInputParam, ref MovingAvgOutputParam APIOutputParam);