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


C# GCHandle类代码示例

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


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

示例1: CreateFirstBridge

	static void CreateFirstBridge () {
		Bridge b = new Bridge() {
			__test = 0,
			id = "first",
		};
		weak_track_handle = GCHandle.Alloc (b, GCHandleType.WeakTrackResurrection);
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:sgen-bridge-gchandle.cs

示例2: CreateSecondBridge

	static void CreateSecondBridge () {
		Bridge b = new Bridge() {
			__test = 1,
			id = "second",
		};
		weak_track_handle2 = GCHandle.Alloc (b, GCHandleType.WeakTrackResurrection);
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:sgen-bridge-gchandle.cs

示例3: Update

    void Update()
    {
        if (state == 0) {
            AndroidJavaClass UnityOpenCVLoaderJava = new AndroidJavaClass(UNITY_OPENCV_LOADER);
            var b = UnityOpenCVLoaderJava.CallStatic<Boolean>("isSuccess");
            if (b) {
                state = 1;
            }
        } else if (state == 1) {
            if (cameraInstance == IntPtr.Zero) cameraInstance = CreateCameraInstance ();

            if (Open (cameraInstance, 0, width, height)) {
                texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
                pixels = texture.GetPixels32 ();
                pixelsHandle = GCHandle.Alloc (pixels, GCHandleType.Pinned);
                pixelsPtr = pixelsHandle.AddrOfPinnedObject ();
                GetComponent<Renderer>().material.mainTexture = texture;
                state = 2;
            } else {
                state = -1;
            }
        } else if (state == 2) {
            getCameraTexture (cameraInstance, pixelsPtr, width, height);
            texture.SetPixels32 (pixels);
            texture.Apply ();
        }
    }
开发者ID:rinsyan0518,项目名称:UnityOpenCV,代码行数:27,代码来源:OpenCVCamera.cs

示例4: Update

    // Update is called once per frame
    void Update()
    {
        // off-screen rendering
        var camtex = RenderTexture.GetTemporary (camWidth, camHeight, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
        myCamera.targetTexture = camtex;
        myCamera.Render ();
        RenderTexture.active = camtex;

        tex.ReadPixels (new Rect (0, 0, camtex.width, camtex.height), 0, 0);
        tex.Apply ();

        // Convert texture to ptr
        texturePixels_       = tex.GetPixels32();
        texturePixelsHandle_ = GCHandle.Alloc(texturePixels_, GCHandleType.Pinned);
        texturePixelsPtr_    = texturePixelsHandle_.AddrOfPinnedObject();

        // Show a window
        fullWindow (windowName, displayNum, texturePixelsPtr_, camWidth, camHeight);

        texturePixelsHandle_.Free();

        RenderTexture.active = null;
        RenderTexture.ReleaseTemporary (camtex);
        myCamera.targetTexture = null;
    }
开发者ID:kurepasu0731,项目名称:ProjectionMapping,代码行数:26,代码来源:multiWindow.cs

示例5: DoLoadBank

	private static AKRESULT DoLoadBank(string in_bankPath)
	{
		ms_www = new WWW(in_bankPath);
		while( ! ms_www.isDone )
		{
#if ! UNITY_METRO
			System.Threading.Thread.Sleep(WaitMs);
#endif // #if ! UNITY_METRO
		}

		uint in_uInMemoryBankSize = 0;
		try
		{
			ms_pinnedArray = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
			ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
			in_uInMemoryBankSize = (uint)ms_www.bytes.Length;	
		}
		catch
		{
			return AKRESULT.AK_Fail;
		}
		
		AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);
		
		return result;
	}
开发者ID:Arpit0492,项目名称:Unity,代码行数:26,代码来源:AkInMemBankLoader.cs

示例6: CreateBuffer

	private void CreateBuffer(int width, int height)
	{
		// Free buffer if it's too small
		if (_frameHandle.IsAllocated && _frameData != null)
		{
			if (_frameData.Length < _frameWidth * _frameHeight)
			{
				FreeBuffer();
			}
		}
		
		if (_frameData == null)
		{
			_frameWidth = width;
			_frameHeight = height;
			_frameData = new Color32[_frameWidth * _frameHeight];
			_frameHandle = GCHandle.Alloc(_frameData, GCHandleType.Pinned);
			_framePointer = _frameHandle.AddrOfPinnedObject();
			
#if TEXTURETEST
			_testTexture = new Texture2D(_frameWidth ,_frameHeight, TextureFormat.ARGB32, false, false);
			_testTexture.Apply(false, false);
#endif
		}
	}
开发者ID:vovo5558,项目名称:NewScopePlus,代码行数:25,代码来源:AVProLiveCameraGrabber.cs

示例7: Main

    public static int Main()
    {
        int[] arr = new int[1000];
        GCHandle[] arrhandle = new GCHandle[10000]; // array of handles to the same object
        IntPtr[] oldaddress = new IntPtr[10000];        // store old addresses
        IntPtr[] newaddress = new IntPtr[10000];        // store new addresses

        for (int i = 0; i < 10000; i++)
        {
            arrhandle[i] = GCUtil.Alloc(arr, GCHandleType.Pinned);
            oldaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        for (int i = 0; i < 10000; i++)
        {
            newaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
        }

        for (int i = 0; i < 10000; i++)
        {
            if (oldaddress[i] != newaddress[i])
            {
                Console.WriteLine("Test failed");
                return 1;
            }
        }

        Console.WriteLine("Test passed");
        return 100;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:33,代码来源:PinnedMultiple.cs

示例8: CreateObj

        public CreateObj()
        {
            obj = new Dummy();
            Console.WriteLine("Allocating a Weak handle to object..");
            handle = GCHandle.Alloc(obj, GCHandleType.Weak);

            // making a copy of the handle
            copy = handle;
        }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:9,代码来源:HandleCopy.cs

示例9: RegisterCommandCallback

    public static void RegisterCommandCallback(CommandCallbackDelegate fun)
    {
        _gcHandle = GCHandle.Alloc(fun);

        if (IntPtr.Size == 8)
            RegisterCommandCallback_x64(fun);
        else
            RegisterCommandCallback_x86(fun);
    }
开发者ID:hhahh2011,项目名称:CH.Study,代码行数:9,代码来源:GoogleV8Engine.cs

示例10: Matrix

    public Matrix(int size)
    {
        if (!_validSizes.Contains(size)) throw new ArgumentOutOfRangeException("size");
        _size = size;
        _data = new int[size * size];

        _dataPtrHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
        _dataPtr = (int*)_dataPtrHandle.AddrOfPinnedObject().ToPointer();
    }
开发者ID:Farouq,项目名称:semclone,代码行数:9,代码来源:Matrix.cs

示例11: Start

	// Use this for initialization
	void Start () {
        camera_ = getCamera(device);
        setCameraProp(camera_, width, height, fps);
        texture_ = new Texture2D(width, height, TextureFormat.ARGB32, false);
        pixels_ = texture_.GetPixels32();
        pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
        pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
        GetComponent<Renderer>().material.mainTexture = texture_;
    }
开发者ID:kurepasu0731,项目名称:ProjectingLight,代码行数:10,代码来源:WebCamManager_native.cs

示例12: alloc_many

 static void alloc_many()
 {
     int
     small_count
     =
     count
     /
     2;
     GCHandle[]
     more
     =
     new
     GCHandle
     [small_count];
     int
     i;
     for
     (i
     =
     0;
     i
     <
     small_count;
     ++i)
     {
     GCHandleType
     t
     =
     (GCHandleType)
     (i
     &
     3);
     more
     [i]
     =
     GCHandle.Alloc
     (i,
     t);
     }
     for
     (i
     =
     0;
     i
     <
     small_count;
     ++i)
     {
     more
     [i].Free
     ();
     }
     Console.WriteLine
     ("alloc many: {0}",
     small_count);
 }
开发者ID:robertmichaelwalsh,项目名称:Multilex,代码行数:56,代码来源:gchandle-stress.cs

示例13: Cleanup

    private void Cleanup(GCHandle[] argStrHandles, GCHandle argPtrsHandle,
                                       IntPtr gsInstancePtr)
    {
        for (int i = 0; i < argStrHandles.Length; i++)
                argStrHandles[i].Free();

            argPtrsHandle.Free();
            ExitAPI(gsInstancePtr);
            DeleteAPIInstance(gsInstancePtr);
    }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:10,代码来源:PdfToPng.cs

示例14: GetContextHandle

 public IntPtr GetContextHandle()
 {
     if ((_selfGCHandle.IsAllocated == false))
     {
         _selfGCHandle = GCHandle.Alloc(
                             this,
                             GCHandleType.Normal);
     }
     return GCHandle.ToIntPtr(_selfGCHandle);
 }
开发者ID:niemyjski,项目名称:corert,代码行数:10,代码来源:CallbackContext.cs

示例15: deterministicStaticInit

 private static void deterministicStaticInit()
 {
     __noData = (IntPtr) (-1);
     __defaultCmdSpace = (IntPtr) (-1);
     modFlags = ApiGroup.Off;
     modIdentity = string.Empty;
     ctrlCallback = new CtrlCB(Bid.SetApiGroupBits);
     cookieObject = new BindingCookie();
     hCookie = GCHandle.Alloc(cookieObject, GCHandleType.Pinned);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:Bid.cs


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