当前位置: 首页>>代码示例>>C#>>正文


C# GCHandle.AddrOfPinnedObject方法代码示例

本文整理汇总了C#中System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject方法的典型用法代码示例。如果您正苦于以下问题:C# GCHandle.AddrOfPinnedObject方法的具体用法?C# GCHandle.AddrOfPinnedObject怎么用?C# GCHandle.AddrOfPinnedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.InteropServices.GCHandle的用法示例。


在下文中一共展示了GCHandle.AddrOfPinnedObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FFTWtest

        // Initializes FFTW and all arrays
        // n: Logical size of the transform
        public FFTWtest(int n)
        {
            System.Console.WriteLine("Starting test with n = " + n + " complex numbers");
            fftLength = n;

            // create two unmanaged arrays, properly aligned
            pin = fftwf.malloc(n * 8);
            pout = fftwf.malloc(n * 8);

            // create two managed arrays, possibly misalinged
            // n*2 because we are dealing with complex numbers
            fin = new float[n * 2];
            fout = new float[n * 2];
            // and two more for double FFTW
            din = new double[n * 2];
            dout = new double[n * 2];

            // get handles and pin arrays so the GC doesn't move them
            hin = GCHandle.Alloc(fin, GCHandleType.Pinned);
            hout = GCHandle.Alloc(fout, GCHandleType.Pinned);
            hdin = GCHandle.Alloc(din, GCHandleType.Pinned);
            hdout = GCHandle.Alloc(dout, GCHandleType.Pinned);

            // create a few test transforms
            fplan1 = fftwf.dft_1d(n, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
            fplan2 = fftwf.dft_1d(n, hin.AddrOfPinnedObject(), hout.AddrOfPinnedObject(),
                fftw_direction.Forward, fftw_flags.Estimate);
            fplan3 = fftwf.dft_1d(n, hout.AddrOfPinnedObject(), pin,
                fftw_direction.Backward, fftw_flags.Measure);
            // end with transforming back to original array
            fplan4 = fftwf.dft_1d(n, hout.AddrOfPinnedObject(), hin.AddrOfPinnedObject(),
                fftw_direction.Backward, fftw_flags.Estimate);
            // and check a quick one with doubles, just to be sure
            fplan5 = fftw.dft_1d(n, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(),
                fftw_direction.Backward, fftw_flags.Measure);

            // create a managed plan as well
            min = new fftw_complexarray(din);
            mout = new fftw_complexarray(dout);
            mplan = fftw_plan.dft_1d(n, min, mout, fftw_direction.Forward, fftw_flags.Estimate);

            // fill our arrays with an arbitrary complex sawtooth-like signal
            for (int i = 0; i < n * 2; i++)
                fin[i] = i % 50;
            for (int i = 0; i < n * 2; i++)
                fout[i] = i % 50;
            for (int i = 0; i < n * 2; i++)
                din[i] = i % 50;

            // copy managed arrays to unmanaged arrays
            Marshal.Copy(fin, 0, pin, n * 2);
            Marshal.Copy(fout, 0, pout, n * 2);
        }
开发者ID:pacificIT,项目名称:FFTWSharp,代码行数:55,代码来源:FFTWtest.cs

示例2: Invoke

        private int Invoke(SOCKET socket)
        {
            _recvOverlapped.hEvent = SocketImports.WSACreateEvent();
            if (_recvOverlapped.hEvent == IntPtr.Zero)
            {
                // dead, close socket?
                return -1;
            }

            _gcWSABuffer = GCHandle.Alloc(_WSABuffer, GCHandleType.Pinned);
            var lpWSABuffer = (WSABuffer*)_gcWSABuffer.AddrOfPinnedObject();

            _gcRecvOverlapped = GCHandle.Alloc(_recvOverlapped, GCHandleType.Pinned);
            var plRecvOverlapped = (WSAOverlapped*)_gcRecvOverlapped.AddrOfPinnedObject();

            int rc = SocketImports.WSARecv(socket, lpWSABuffer, 1, out _bytesTransferred, ref _socketFlags, plRecvOverlapped, IntPtr.Zero);

            _gcWSABuffer.Free();
            _gcRecvOverlapped.Free();

            if (rc == SocketImports.SOCKET_ERROR)
            {
                int err = SocketImports.WSAGetLastError();
                if (SocketImports.WSA_IO_PENDING != err)
                {
                    Console.WriteLine("WSARecv failed with error: {0}/{1}", rc, err);
                }
            }

            return rc;
        }
开发者ID:shhsu,项目名称:corefxlab,代码行数:31,代码来源:WSARecvCall.cs

示例3: BufferData

        public static VBO<Vector3> BufferData(VBO<Vector3> vbo, Vector3[] data, GCHandle handle)
        {
            if (vbo == null) return new VBO<Vector3>(data, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);

            vbo.BufferSubDataPinned(BufferTarget.ArrayBuffer, 12 * data.Length, handle.AddrOfPinnedObject());
            return vbo;
        }
开发者ID:giawa,项目名称:ee2015presentation,代码行数:7,代码来源:Common.cs

示例4: IntegralImage2

        /// <summary>
        ///   Constructs a new Integral image of the given size.
        /// </summary>
        /// 
        protected IntegralImage2(int width, int height, bool computeTilted)
        {
            this.width = width;
            this.height = height;

            this.nWidth = width + 1;
            this.nHeight = height + 1;

            this.tWidth = width + 2;
            this.tHeight = height + 2;

            this.nSumImage = new int[nHeight, nWidth];
            this.nSumHandle = GCHandle.Alloc(nSumImage, GCHandleType.Pinned);
            this.nSum = (int*)nSumHandle.AddrOfPinnedObject().ToPointer();

            this.sSumImage = new int[nHeight, nWidth];
            this.sSumHandle = GCHandle.Alloc(sSumImage, GCHandleType.Pinned);
            this.sSum = (int*)sSumHandle.AddrOfPinnedObject().ToPointer();

            if (computeTilted)
            {
                this.tSumImage = new int[tHeight, tWidth];
                this.tSumHandle = GCHandle.Alloc(tSumImage, GCHandleType.Pinned);
                this.tSum = (int*)tSumHandle.AddrOfPinnedObject().ToPointer();
            }
        }
开发者ID:egormozzharov,项目名称:ViolaJones,代码行数:30,代码来源:IntegralImage2.cs

示例5: CommitToSolver

        public override void CommitToSolver()
        {
            if (skinIndices != null && skinPoints != null && skinNormals != null && skinRadiiBackstops != null && skinStiffnesses != null){

                Oni.UnpinMemory(skinIndicesHandle);
                Oni.UnpinMemory(skinPointsHandle);
                Oni.UnpinMemory(skinNormalsHandle);
                Oni.UnpinMemory(skinRadiiBackstopsHandle);
                Oni.UnpinMemory(skinStiffnessesHandle);

                skinIndicesHandle = Oni.PinMemory(skinIndices);
                skinPointsHandle = Oni.PinMemory(skinPoints);
                skinNormalsHandle = Oni.PinMemory(skinNormals);
                skinRadiiBackstopsHandle = Oni.PinMemory(skinRadiiBackstops);
                skinStiffnessesHandle = Oni.PinMemory(skinStiffnesses);

                Oni.SetSkinConstraints(solver.Solver,
                                       skinIndicesHandle.AddrOfPinnedObject(),
                                       skinPointsHandle.AddrOfPinnedObject(),
                                       skinNormalsHandle.AddrOfPinnedObject(),
                                       skinRadiiBackstopsHandle.AddrOfPinnedObject(),
                                       skinStiffnessesHandle.AddrOfPinnedObject());

                CommitActive();
            }
        }
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:26,代码来源:ObiSkinConstraintGroup.cs

示例6: ColorCodec

 public ColorCodec(RGBAPixel[] pixels)
 {
     _srcCount = pixels.Length;
     _handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
     _pData = (RGBAPixel*)_handle.AddrOfPinnedObject();
     Evaluate();
 }
开发者ID:blahblahblahblah831,项目名称:brawltools2,代码行数:7,代码来源:ColorCodec.cs

示例7: Execute

        public void Execute()
        {
            // Create GS Instance (GS-API)
            gsapi_new_instance(out _gsInstancePtr, IntPtr.Zero);
            // Build Argument Arrays
            _gsArgStrHandles = new GCHandle[_gsParams.Count];
            _gsArgPtrs = new IntPtr[_gsParams.Count];

            // Populate Argument Arrays
            for (int i = 0; i < _gsParams.Count; i++)
            {
                _gsArgStrHandles[i] = GCHandle.Alloc(System.Text.ASCIIEncoding.ASCII.GetBytes(_gsParams[i].ToString()), GCHandleType.Pinned);
                _gsArgPtrs[i] = _gsArgStrHandles[i].AddrOfPinnedObject();
            }

            // Allocate memory that is protected from Garbage Collection
            _gsArgPtrsHandle = GCHandle.Alloc(_gsArgPtrs, GCHandleType.Pinned);
            // Init args with GS instance (GS-API)
            gsapi_init_with_args(_gsInstancePtr, _gsArgStrHandles.Length, _gsArgPtrsHandle.AddrOfPinnedObject());
            // Free unmanaged memory
            for (int i = 0; i < _gsArgStrHandles.Length; i++)
                _gsArgStrHandles[i].Free();
            _gsArgPtrsHandle.Free();

            // Exit the api (GS-API)
            gsapi_exit(_gsInstancePtr);
            // Delete GS Instance (GS-API)
            gsapi_delete_instance(_gsInstancePtr);
        }
开发者ID:Bzdun,项目名称:NewProject,代码行数:29,代码来源:WGScript.cs

示例8: AdaptAudioDataImpl

        private unsafe void AdaptAudioDataImpl()
        {
            var isStereo = WaveFormat.Channels == 2;
            
            // allocate the new audio buffer 
            var sampleRateRatio = Math.Min(1, WaveFormat.SampleRate / (float)SoundEffectInstance.SoundEffectInstanceFrameRate); // we don't down-sample in current version
            var newWaveDataSize = (int)Math.Floor(WaveDataSize / sampleRateRatio) * (isStereo ? 1 : 2);
            WaveDataArray = new byte[newWaveDataSize];

            fixed (byte* pNewWaveData = WaveDataArray)
            {
                // re-sample the audio data
                if (Math.Abs(sampleRateRatio - 1f) < MathUtil.ZeroTolerance && !isStereo)
                    DuplicateTracks(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize);
                else if (Math.Abs(sampleRateRatio - 0.5f) < MathUtil.ZeroTolerance)
                    UpSampleByTwo(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, WaveFormat.Channels, !isStereo);
                else
                    UpSample(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, sampleRateRatio, WaveFormat.Channels, !isStereo);
            }

            // update the wave data buffer
            pinnedWaveData = GCHandle.Alloc(WaveDataArray, GCHandleType.Pinned);
            WaveDataPtr = pinnedWaveData.AddrOfPinnedObject();
            WaveDataSize = newWaveDataSize;
            
            // Free unused anymore C# data buffer
            Utilities.FreeMemory(nativeDataBuffer);
            nativeDataBuffer = IntPtr.Zero;
        }
开发者ID:cg123,项目名称:xenko,代码行数:29,代码来源:SoundEffect.Android.cs

示例9: AVPacket

        public AVPacket()
        {
            AutoGen.AVPacket packet = new AutoGen.AVPacket();
            _handle = GCHandle.Alloc(packet, GCHandleType.Pinned);

            _packet = (AutoGen.AVPacket*)_handle.AddrOfPinnedObject().ToPointer();
        }
开发者ID:nbomeroglu37,项目名称:FFmpeg.Wrapper,代码行数:7,代码来源:AVPacket.cs

示例10: AllocateData

      private IntPtr AllocateData(CvEnum.DepthType type, int channels, int totalInBytes)
      {
         FreeData();

         switch (type)
         {
            //case CvEnum.DepthType.Cv8U:
            //   _data = new byte[totalInBytes];
            //   break;
            case CvEnum.DepthType.Cv8S:
               _data = new SByte[totalInBytes];
               break;
            case CvEnum.DepthType.Cv16U:
               _data = new UInt16[totalInBytes >> 1];
               break;
            case CvEnum.DepthType.Cv16S:
               _data = new Int16[totalInBytes >> 1];
               break;
            case CvEnum.DepthType.Cv32S:
               _data = new Int32[totalInBytes >> 2];
               break;
            case CvEnum.DepthType.Cv32F:
               _data = new float[totalInBytes >> 2];
               break;
            case CvEnum.DepthType.Cv64F:
               _data = new double[totalInBytes >> 3];
               break;
            default:
               _data = new byte[totalInBytes];
               break;
         }

         _dataHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
         return _dataHandle.AddrOfPinnedObject();
      }
开发者ID:Delaley,项目名称:emgucv,代码行数:35,代码来源:MatDataAllocator.cs

示例11: Initialize

 protected override void Initialize()
 {
     optionsgchandle = GCHandle.Alloc(options, GCHandleType.Pinned);
     opaque = optionsgchandle.AddrOfPinnedObject();
     hoedown_html_toc_renderer_new(ref callbacks, opaque, 0);
     base.Initialize();
 }
开发者ID:hoedown,项目名称:hoedown.net,代码行数:7,代码来源:TableOfContentRenderer.cs

示例12: DecomposedResult

 public unsafe DecomposedResult(int maxInstructions)
 {
     MaxInstructions = maxInstructions;
       _instMem = new byte[maxInstructions * sizeof(DecomposedInstructionStruct)];
       _gch = GCHandle.Alloc(_instMem, GCHandleType.Pinned);
       _instructionsPointer = (DecomposedInstructionStruct *)_gch.AddrOfPinnedObject();
 }
开发者ID:damageboy,项目名称:distorm-net,代码行数:7,代码来源:DecomposedResult.cs

示例13: MarshalMultipleValueStructure

        public MarshalMultipleValueStructure(byte[] key, byte[][] values)
        {
            if (values == null)
                throw new ArgumentNullException(nameof(values));

            _size = GetSize(values);
            _count = GetCount(values);
            _flattened = values.SelectMany(x => x).ToArray();
            _valuesHandle = GCHandle.Alloc(_flattened, GCHandleType.Pinned);

            _key = key;
            _keyHandle = GCHandle.Alloc(_key, GCHandleType.Pinned);

            Values = new[]
            {
                new ValueStructure
                {
                    size = new IntPtr(_size),
                    data = _valuesHandle.AddrOfPinnedObject()
                },
                new ValueStructure
                {
                    size = new IntPtr(_count)
                }
            };

            Key = new ValueStructure
            {
                size = new IntPtr(_key.Length),
                data = _keyHandle.AddrOfPinnedObject()
            };
        }
开发者ID:sebastienros,项目名称:Lightning.NET,代码行数:32,代码来源:MarshalMultipleValueStructure.cs

示例14: FpuRegisters

 public FpuRegisters()
 {
     m_Regs = new ulong[32];
     m_RegHandle = GCHandle.Alloc(m_Regs, GCHandleType.Pinned);
     m_RegsPtr = m_RegHandle.AddrOfPinnedObject();
     /* TODO: Free handle on dispose */
 }
开发者ID:RonnChyran,项目名称:Soft64-Bryan,代码行数:7,代码来源:FpuRegisters.cs

示例15: MemoryPoolSlab

 public MemoryPoolSlab(byte[] data)
 {
     _data = data;
     _gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
     _nativePointer = _gcHandle.AddrOfPinnedObject();
     _isActive = true;
 }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:7,代码来源:MemoryPoolSlab.cs


注:本文中的System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。