• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# InteropServices.GCHandle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



GCHandle类属于System.Runtime.InteropServices命名空间,在下文中一共展示了GCHandle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: FreeString

        public static void FreeString(ref GCHandle handle)
        {
            if (handle == NullHandle)
                return;

            handle.Free();
        }
开发者ID:RaptorFactor,项目名称:Steam4NET,代码行数:7,代码来源:InteropHelp.cs


示例2: LoadFromMemory

        public unsafe static Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
        {
            using (var memoryStream = new UnmanagedMemoryStream((byte*)pSource, size))
            using (var bitmap = (Bitmap)BitmapFactory.DecodeStream(memoryStream))
            {
                var bitmapData = bitmap.LockPixels();
            
                var image = Image.New2D(bitmap.Width, bitmap.Height, 1, PixelFormat.B8G8R8A8_UNorm, 1, bitmap.RowBytes);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                // Directly load image as RGBA instead of BGRA, because OpenGL ES devices don't support it out of the box (extension).
                CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#else
                Utilities.CopyMemory(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#endif
                bitmap.UnlockPixels();
            
                if (handle != null)
                    handle.Value.Free();
                else if (!makeACopy)
                    Utilities.FreeMemory(pSource);
            
                return image;
            }

        }
开发者ID:Powerino73,项目名称:paradox,代码行数:25,代码来源:StandardImageHelper.Android.cs


示例3: 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


示例4: 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


示例5: SQLite3

    internal SQLite3(SQLiteDateFormats fmt)
      : base(fmt)
    {
#if MONOTOUCH
      gch = GCHandle.Alloc (this);
#endif
    }
开发者ID:GirlD,项目名称:mono,代码行数:7,代码来源:SQLite3.cs


示例6: TtsBufferManaged

 public TtsBufferManaged()
 {
     _value = new TTS_BUFFER_T();
     _pinHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
     _value.MaxBufferLength = TTS_BUFFER_T.BufferSize;
     _value.DataPtr = Marshal.AllocHGlobal(TTS_BUFFER_T.BufferSize);
 }
开发者ID:Xaekai,项目名称:SharpTalk,代码行数:7,代码来源:TTS_BUFFER_T.cs


示例7: LoadFromMemory

        public static unsafe Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
        {
            var stream = new BinarySerializationReader(new NativeMemoryStream((byte*)pSource, size));

            // Read and check magic code
            var magicCode = stream.ReadUInt32();
            if (magicCode != MagicCode)
                return null;

            // Read header
            var imageDescription = new ImageDescription();
            imageDescriptionSerializer.Serialize(ref imageDescription, ArchiveMode.Deserialize, stream);

            if (makeACopy)
            {
                var buffer = Utilities.AllocateMemory(size);
                Utilities.CopyMemory(buffer, pSource, size);
                pSource = buffer;
                makeACopy = false;
            }

            var image = new Image(imageDescription, pSource, 0, handle, !makeACopy);

            var totalSizeInBytes = stream.ReadInt32();
            if (totalSizeInBytes != image.TotalSizeInBytes)
                throw new InvalidOperationException("Image size is different than expected.");

            // Read image data
            stream.Serialize(image.DataPointer, image.TotalSizeInBytes);

            return image;
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:32,代码来源:ImageHelper.cs


示例8: Unpin

        public void Unpin()
        {
            if (_operationHandle.IsAllocated)
            {
                Debug.Assert(_handlesOpenWithCallback == 0);

                // This method only gets called when the WinHTTP request/websocket handles are fully closed and thus
                // all async operations are done. So, it is safe at this point to unpin the buffers and release
                // the strong GCHandle for this object.
                if (_cachedReceivePinnedBuffer.IsAllocated)
                {
                    _cachedReceivePinnedBuffer.Free();
                    _cachedReceivePinnedBuffer = default(GCHandle);
                }

                if (_cachedSendPinnedBuffer.IsAllocated)
                {
                    _cachedSendPinnedBuffer.Free();
                    _cachedSendPinnedBuffer = default(GCHandle);
                }

                _operationHandle.Free();
                _operationHandle = default(GCHandle);
            }
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:25,代码来源:WinHttpWebSocketState.cs


示例9: 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


示例10: Draw3DPlotLeft

        public static void Draw3DPlotLeft(float[] data, float depth, Vector3 color, Matrix4 viewMatrix, bool log = false)
        {
            if (data.Length < 441) throw new ArgumentException("The argument data was not the correct length.");

            for (int i = 0; i < fftData.Length; i++)
                fftData[i] = new Vector3((log ? Math.Log10(i) * 166 : i) - 441 / 2f, Math.Max(-200, Math.Min(200, 200 * data[i])), depth);
                //fftData[i] = new Vector3(i - 441 / 2f, Math.Max(-200, Math.Min(200, 200 * data[i])), depth);

            if (fftVAO == null)
            {
                int[] array = new int[441];
                for (int i = 0; i < array.Length; i++) array[i] = i;

                fftHandle = GCHandle.Alloc(fftData, GCHandleType.Pinned);
                fftVBO = BufferData(fftVBO, fftData, fftHandle);
                fftVAO = new VAO<Vector3>(Shaders.SimpleColoredShader, fftVBO, "in_position", new VBO<int>(array, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw));
                fftVAO.DrawMode = BeginMode.LineStrip;
            }
            else fftVBO = BufferData(fftVBO, fftData, fftHandle);

            Shaders.SimpleColoredShader.Use();
            Shaders.SimpleColoredShader["projectionMatrix"].SetValue(Program.uiProjectionMatrix);
            Shaders.SimpleColoredShader["viewMatrix"].SetValue(viewMatrix);
            Shaders.SimpleColoredShader["modelMatrix"].SetValue(Matrix4.CreateTranslation(new Vector3(72 + 441 / 2f, 288, 0)));
            Shaders.SimpleColoredShader["color"].SetValue(color);
            fftVAO.Draw();
        }
开发者ID:giawa,项目名称:ee2015presentation,代码行数:27,代码来源:Common.cs


示例11: WaveRecorder

 public WaveRecorder(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferAvailableDelegate bufferAvailable)
 {
     this._bufferAvailable = bufferAvailable;
       PaStreamParameters inputParameters = new PaStreamParameters();
       inputParameters.device = deviceIndex;
       inputParameters.channelCount = 2;
       inputParameters.suggestedLatency = 0.0;
       inputParameters.sampleFormat = PaSampleFormat.PaFloat32;
       PaError paError1 = PortAudioAPI.Pa_IsFormatSupported(ref inputParameters, IntPtr.Zero, sampleRate);
       if (paError1 != PaError.paNoError)
     throw new ApplicationException(paError1.ToString());
       this._gcHandle = GCHandle.Alloc((object) this);
       PaError paError2 = PortAudioAPI.Pa_OpenStream(out this._streamHandle, ref inputParameters, IntPtr.Zero, sampleRate, (uint) framesPerBuffer, PaStreamFlags.PaNoFlag, this._paCallback, (IntPtr) this._gcHandle);
       if (paError2 != PaError.paNoError)
       {
     this._gcHandle.Free();
     throw new ApplicationException(paError2.ToString());
       }
       PaError paError3 = PortAudioAPI.Pa_StartStream(this._streamHandle);
       if (paError3 != PaError.paNoError)
       {
     int num = (int) PortAudioAPI.Pa_CloseStream(this._streamHandle);
     this._gcHandle.Free();
     throw new ApplicationException(paError3.ToString());
       }
 }
开发者ID:zloiia,项目名称:sdrsrc,代码行数:26,代码来源:WaveRecorder.cs


示例12: Main

        static void Main(string[] args)
        {
            Console.Write("Enter Passphrase: ");
            using (var passphrase = GetPassphraseFromConsole())
            {
                Console.WriteLine("Your password:");

                RuntimeHelpers.PrepareConstrainedRegions();

                unsafe
                {
                    var arPass = new char[passphrase.Length];

                    var handle = new GCHandle();

                    System.IntPtr ptr = System.IntPtr.Zero;

                    ptr = Marshal.SecureStringToBSTR(passphrase);

                    char* ptrPassword = (char*)ptr;

                    RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
                        (uData) =>
                        {
                            handle = GCHandle.Alloc(arPass, System.Runtime.InteropServices.GCHandleType.Pinned);

                            ptrPassword = (char*)ptr;

                            char* ptrArPass = (char*)handle.AddrOfPinnedObject();

                            for (var ii = 0; ii < arPass.Length; ii++)
                            {
                                ptrArPass[ii] = ptrPassword[ii];
                            }

                            Console.WriteLine(arPass);
                        },

                        (uData, exceptionThrown) =>
                        {
                            if (exceptionThrown)
                            {
                                Console.WriteLine("Exception thrown.");
                            }

                            Marshal.ZeroFreeBSTR(ptr);

                            for (var ii = 0; ii < arPass.Length; ii++)
                            {
                                arPass[ii] = '\0';
                            }

                            handle.Free();

                        },
                            null
                        );
                }
            }
        }
开发者ID:blombas,项目名称:StructuredSight,代码行数:60,代码来源:Program.cs


示例13: PSP

		public PSP(CoreComm comm, string isopath)
		{
			ServiceProvider = new BasicServiceProvider(this);
			if (attachedcore != null)
			{
				attachedcore.Dispose();
				attachedcore = null;
			}
			CoreComm = comm;

			logcallback = new PPSSPPDll.LogCB(LogCallbackFunc);

			bool good = PPSSPPDll.init(isopath, logcallback);
			LogFlush();
			if (!good)
				throw new Exception("PPSSPP Init failed!");
			vidhandle = GCHandle.Alloc(screenbuffer, GCHandleType.Pinned);
			PPSSPPDll.setvidbuff(vidhandle.AddrOfPinnedObject());

			CoreComm.VsyncDen = 1;
			CoreComm.VsyncNum = 60;
			CoreComm.RomStatusDetails = "It puts the scythe in the chicken or it gets the abyss again!";

			attachedcore = this;
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:25,代码来源:PSP.cs


示例14: DvProviderUpnpOrgSwitchPower1

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="aDevice">Device which owns this provider</param>
 protected DvProviderUpnpOrgSwitchPower1(DvDevice aDevice)
     : base(aDevice, "upnp.org", "SwitchPower", 1)
 {
     iGch = GCHandle.Alloc(this);
     iPropertyStatus = new PropertyBool(new ParameterBool("Status"));
     AddProperty(iPropertyStatus);
 }
开发者ID:wifigeek,项目名称:ohNet,代码行数:11,代码来源:DvUpnpOrgSwitchPower1.cs


示例15: ReadStart

 public void ReadStart(
     Func<UvStreamHandle, int, object, Libuv.uv_buf_t> allocCallback,
     Action<UvStreamHandle, int, Exception, object> readCallback,
     object state)
 {
     if (_readVitality.IsAllocated)
     {
         throw new InvalidOperationException("TODO: ReadStop must be called before ReadStart may be called again");
     }
     try
     {
         _allocCallback = allocCallback;
         _readCallback = readCallback;
         _readState = state;
         _readVitality = GCHandle.Alloc(this, GCHandleType.Normal);
         _uv.read_start(this, _uv_alloc_cb, _uv_read_cb);
     }
     catch
     {
         _allocCallback = null;
         _readCallback = null;
         _readState = null;
         if (_readVitality.IsAllocated)
         {
             _readVitality.Free();
         }
         throw;
     }
 }
开发者ID:justkao,项目名称:KestrelHttpServer,代码行数:29,代码来源:UvStreamHandle.cs


示例16: ImageHelper

        /// <summary>
        /// imageHelper Constructor passing in width and height and whether we want to tilt the feature
        /// </summary>
        /// <param name="pWidth"></param>
        /// <param name="pHeight"></param>
        /// <param name="pComputeTilted"></param>
        protected ImageHelper(int pWidth, int pHeight, bool pComputeTilted)
        {
            // figure out the width and height for each
            this.iWidth = pWidth;
            this.iHeight = pHeight;

            this.nWidth = pWidth + 1;
            this.nHeight = pHeight + 1;

            this.tWidth = pWidth + 2;
            this.tHeight = pHeight + 2;

            // grab the image and create a GCHandle pointer to the memory for that image
            this.integralImage = new int[nHeight, nWidth];
            this.intPointer = GCHandle.Alloc(integralImage, GCHandleType.Pinned);
            this.intImage = (int*)intPointer.AddrOfPinnedObject().ToPointer();

            this.squaredIntImage = new int[nHeight, nWidth];
            this.squaredPointer = GCHandle.Alloc(squaredIntImage, GCHandleType.Pinned);
            this.squaredImage = (int*)squaredPointer.AddrOfPinnedObject().ToPointer();

            if (pComputeTilted)
            {
                this.tiltedIntImage = new int[tHeight, tWidth];
                this.tiltedPointer = GCHandle.Alloc(tiltedIntImage, GCHandleType.Pinned);
                this.tiltedImage = (int*)tiltedPointer.AddrOfPinnedObject().ToPointer();
            }
        }
开发者ID:Jedwondle,项目名称:seniorProject,代码行数:34,代码来源:ImageHelper.cs


示例17: 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


示例18: 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


示例19: 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


示例20: Shutdown

 public void Shutdown(UvStreamHandle handle, Action<UvShutdownReq, int, object> callback, object state)
 {
     _callback = callback;
     _state = state;
     _pin = GCHandle.Alloc(this, GCHandleType.Normal);
     _uv.shutdown(this, handle, _uv_shutdown_cb);
 }
开发者ID:njmube,项目名称:KestrelHttpServer,代码行数:7,代码来源:UvShutdownReq.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# InteropServices.HandleRef类代码示例发布时间:2022-05-26
下一篇:
C# InteropServices.ComTypes类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap