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


C# GCHandle.Free方法代码示例

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


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

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

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

示例3: Main

    public static int Main()
    {
        // The third element needs to be updated if Pinned is no longer the last value in the GCHandleType enum
        long[] invalidValues = { Int32.MinValue, -1, (long)(GCHandleType.Pinned + 1), Int32.MaxValue, UInt32.MaxValue, Int64.MaxValue };
        bool passed = true;

        for (int i = 0; i < invalidValues.Length; i++)
        {
            // GCHandle.Alloc internally casts the GCHandleType to a uint
            Console.WriteLine("Input: {0}, Converted to: {1}", invalidValues[i], (uint)invalidValues[i]);

            GCHandle gch = new GCHandle();
            try
            {
                gch = GCHandle.Alloc(new object(), (GCHandleType)(invalidValues[i]));
                Console.WriteLine("Failed");
                passed = false;
                gch.Free();
            }
            catch (ArgumentOutOfRangeException)
            {
                // caught the expected exception
                Console.WriteLine("Passed");
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught unexpected exception");
                Console.WriteLine(e);
                passed = false;
            }

            Console.WriteLine();
        }

        if (passed)
        {
            Console.WriteLine("Test Passed");
            return 100;
        }

        Console.WriteLine("Test Failed");
        return 1;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:43,代码来源:Alloc_neg2.cs

示例4: Start

	void Start()
	{
		// テクスチャを生成
		texture_ = new Texture2D(10, 10, TextureFormat.RGB24, false);
		// テクスチャの拡大方法をニアレストネイバーに変更
		texture_.filterMode = FilterMode.Point;
		// Color32 型の配列としてテクスチャの参照をもらう
		pixels_ = texture_.GetPixels32();
		// GC されないようにする
		pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
		// そのテクスチャのアドレスをもらう
		pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
		// スクリプトがアタッチされたオブジェクトのテクスチャをコレにする
		GetComponent<Renderer>().material.mainTexture = texture_;
		// ネイティブ側でテクスチャを生成
		create_check_texture(pixels_ptr_, texture_.width, texture_.height, 4);
		// セットして反映させる
		texture_.SetPixels32(pixels_);
		texture_.Apply(false, true);
		// GC 対象にする
		pixels_handle_.Free();
	}
开发者ID:AndroidHMD,项目名称:unity-android-aruco-sample,代码行数:22,代码来源:CheckTexture.cs

示例5: Start

	void Start()
	{
		var path = GetFilePath(imagePath);
		int width, height;
		if (!get_image_size(path, out width, out height)) {
			Debug.LogFormat("{0} was not found", path);
			return;
		}

		texture_ = new Texture2D(width, height, TextureFormat.RGB24, false);
		texture_.filterMode = FilterMode.Point;
		pixels_ = texture_.GetPixels32();
		pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
		pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
		GetComponent<Renderer>().material.mainTexture = texture_;

		read_image(path, pixels_ptr_);

		texture_.SetPixels32(pixels_);
		texture_.Apply();
		pixels_handle_.Free();
	}
开发者ID:AndroidHMD,项目名称:unity-android-aruco-sample,代码行数:22,代码来源:ReadTexture.cs

示例6: LoadFile

    IEnumerator LoadFile()
    {
        ms_www = new WWW(m_bankPath);

        yield return ms_www;

        uint in_uInMemoryBankSize = 0;

        // Allocate an aligned buffer
        try
        {
            ms_pinnedArray = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
            ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
            in_uInMemoryBankSize = (uint)ms_www.bytes.Length;

            // Array inside the WWW object is not aligned. Allocate a new array for which we can guarantee the alignment.
            if( (ms_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0 )
            {
                byte[] alignedBytes = new byte[ms_www.bytes.Length + AK_BANK_PLATFORM_DATA_ALIGNMENT];
                GCHandle new_pinnedArray = GCHandle.Alloc(alignedBytes, GCHandleType.Pinned);
                IntPtr new_pInMemoryBankPtr = new_pinnedArray.AddrOfPinnedObject();
                int alignedOffset = 0;

                // New array is not aligned, so we will need to use an offset inside it to align our data.
                if( (new_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0 )
                {
                    Int64 alignedPtr = (new_pInMemoryBankPtr.ToInt64() + AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) & ~AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK;
                    alignedOffset = (int)(alignedPtr - new_pInMemoryBankPtr.ToInt64());
                    new_pInMemoryBankPtr = new IntPtr(alignedPtr);
                }

                // Copy the bank's bytes in our new array, at the correct aligned offset.
                Array.Copy (ms_www.bytes, 0, alignedBytes, alignedOffset, ms_www.bytes.Length);

                ms_pInMemoryBankPtr = new_pInMemoryBankPtr;
                ms_pinnedArray.Free();
                ms_pinnedArray = new_pinnedArray;
            }
        }
        catch
        {
            yield break;
        }

        AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);
        if( result != AKRESULT.AK_Success )
        {
            Debug.LogError ("AkMemBankLoader: bank loading failed with result " + result.ToString ());
        }
    }
开发者ID:NunezG,项目名称:villeEmergente,代码行数:50,代码来源:AkMemBankLoader.cs

示例7: Free

 public static void Free(ref GCHandle gh)
 {
     gh.Free();
 }
开发者ID:l1183479157,项目名称:coreclr,代码行数:4,代码来源:GCUtil.cs

示例8: CreateSelfSignCertificatePfx

    public static byte[] CreateSelfSignCertificatePfx(
        string x500,
        DateTime startTime,
        DateTime endTime,
        SecureString password)
    {
        byte[] pfxData;

        if (x500 == null)
        {
            x500 = "";
        }

        SystemTime startSystemTime = ToSystemTime(startTime);
        SystemTime endSystemTime = ToSystemTime(endTime);
        string containerName = Guid.NewGuid().ToString();

        GCHandle dataHandle = new GCHandle();
        IntPtr providerContext = IntPtr.Zero;
        IntPtr cryptKey = IntPtr.Zero;
        IntPtr certContext = IntPtr.Zero;
        IntPtr certStore = IntPtr.Zero;
        IntPtr storeCertContext = IntPtr.Zero;
        IntPtr passwordPtr = IntPtr.Zero;
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {
            Check(NativeMethods.CryptAcquireContextW(
                out providerContext,
                containerName,
                null,
                1, // PROV_RSA_FULL
                8)); // CRYPT_NEWKEYSET

            Check(NativeMethods.CryptGenKey(
                providerContext,
                1, // AT_KEYEXCHANGE
                1, // CRYPT_EXPORTABLE
                out cryptKey));

            IntPtr errorStringPtr;
            int nameDataLength = 0;
            byte[] nameData;

            // errorStringPtr gets a pointer into the middle of the x500 string,
            // so x500 needs to be pinned until after we've copied the value
            // of errorStringPtr.
            dataHandle = GCHandle.Alloc(x500, GCHandleType.Pinned);

            if (!NativeMethods.CertStrToNameW(
                0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
                dataHandle.AddrOfPinnedObject(),
                3, // CERT_X500_NAME_STR = 3
                IntPtr.Zero,
                null,
                ref nameDataLength,
                out errorStringPtr))
            {
                string error = Marshal.PtrToStringUni(errorStringPtr);
                throw new ArgumentException(error);
            }

            nameData = new byte[nameDataLength];

            if (!NativeMethods.CertStrToNameW(
                0x00010001, // X509_ASN_ENCODING | PKCS_7_ASN_ENCODING
                dataHandle.AddrOfPinnedObject(),
                3, // CERT_X500_NAME_STR = 3
                IntPtr.Zero,
                nameData,
                ref nameDataLength,
                out errorStringPtr))
            {
                string error = Marshal.PtrToStringUni(errorStringPtr);
                throw new ArgumentException(error);
            }

            dataHandle.Free();

            dataHandle = GCHandle.Alloc(nameData, GCHandleType.Pinned);
            CryptoApiBlob nameBlob = new CryptoApiBlob(
                nameData.Length,
                dataHandle.AddrOfPinnedObject());

            CryptKeyProviderInformation kpi = new CryptKeyProviderInformation();
            kpi.ContainerName = containerName;
            kpi.ProviderType = 1; // PROV_RSA_FULL
            kpi.KeySpec = 1; // AT_KEYEXCHANGE

            certContext = NativeMethods.CertCreateSelfSignCertificate(
                providerContext,
                ref nameBlob,
                0,
                ref kpi,
                IntPtr.Zero, // default = SHA1RSA
                ref startSystemTime,
                ref endSystemTime,
                IntPtr.Zero);
            Check(certContext != IntPtr.Zero);
            dataHandle.Free();
//.........这里部分代码省略.........
开发者ID:EdWeller,项目名称:SoapboxSnap,代码行数:101,代码来源:Certificate.cs

示例9: CreateSelfSignCertificatePfx

    /// <summary>
    /// 自己証明書作成のメソッド本体
    ///   rawData が nullで、自己証明書を新規作成
    ///   rawDate を指定すると、既存の自己証明書の更新
    /// </summary>
    /// <param name="rawData">更新時の証明書バイナリーデータ</param>
    /// <param name="x500">組織名(CN="XXXXX")</param>
    /// <param name="startTime">開始日</param>
    /// <param name="endTime">終了日</param>
    /// <param name="insecurePassword">セキュア パスワード</param>
    /// <returns>証明書データ</returns>
    public static byte[] CreateSelfSignCertificatePfx(
        byte[] rawData,
        string x500,
        DateTime startTime,
        DateTime endTime,
        SecureString password)
    {
        byte[] pfxData;

        if (x500 == null)
        {
            x500 = "";
        }

        SystemTime startSystemTime = ToSystemTime(startTime);
        SystemTime endSystemTime = ToSystemTime(endTime);
        string containerName = Guid.NewGuid().ToString();

        GCHandle dataHandle = new GCHandle();
        IntPtr providerContext = IntPtr.Zero;
        IntPtr cryptKey = IntPtr.Zero;
        IntPtr certContext = IntPtr.Zero;
        IntPtr certStore = IntPtr.Zero;
        IntPtr storeCertContext = IntPtr.Zero;
        IntPtr passwordPtr = IntPtr.Zero;
        IntPtr callerFreeProvOrNCryptKey = IntPtr.Zero;

        // コード本体を制約された実行領域 (CER) として指定します。
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {
            if (password != null)
            {
                // アンマネージ COM タスク アロケーターから割り当てられたメモリ ブロックに、マネージ SecureString オブジェクトの内容をコピーします
                passwordPtr = Marshal.SecureStringToCoTaskMemUnicode(password);
            }

            if (rawData == null)
            {
                // 自己証明書の新規作成用にハンドル(HCRYPTPROV) を取得します(providerContext)

                // cryptographic service provider(CSP)内で キーコンテナに対するハンドル(HCRYPTPROV)を取得します
                Check(NativeMethods.CryptAcquireContextW(
                    out providerContext,
                    containerName,
                    //MS_ENHANCED_PROV,
                    null,
                    PROV_RSA_FULL,
                    CRYPT_NEWKEYSET));

                // ランダムな暗号化用のセッションキーか public/private のキーペアを生成します(HCRYPTKEY)
                Check(NativeMethods.CryptGenKey(
                    providerContext,
                    AT_KEYEXCHANGE,
                    //RSA2048BIT_KEY | CRYPT_EXPORTABLE, // 2048ビットへ変更、標準は1024ビット
                    RSA1024BIT_KEY | CRYPT_EXPORTABLE, // 2048ビットへ変更、標準は1024ビット
                    out cryptKey));
            }
            else
            {
                // 自己証明書の更新用にハンドル(HCRYPTPROV) を取得します(providerContext)

                // 証明書データ(PFX Blob)をインポートします
                CryptoApiBlob certBlob = new CryptoApiBlob();
                certBlob.DataLength = rawData.Length;               // 証明書データをPFX Blobへコピーします
                certBlob.Data = Marshal.AllocHGlobal(certBlob.DataLength);
                Marshal.Copy(rawData, 0, certBlob.Data, rawData.Length);
                Check(NativeMethods.PFXIsPFXBlob(ref certBlob));    // PFX Blobが正常かどうかを確認します
                certStore = NativeMethods.PFXImportCertStore(
                    ref certBlob,
                    passwordPtr,
                    CRYPT_EXPORTABLE | CRYPT_USER_KEYSET);
                Check(certStore != IntPtr.Zero);
                // 証明書を取得します
                certContext = NativeMethods.CertEnumCertificatesInStore(
                    certStore,
                    IntPtr.Zero);
                Check(certContext != IntPtr.Zero);

                // 証明書の private キーを含めて、キーコンテナに対するハンドル(HCRYPTPROV)を取得します
                IntPtr keySpec = IntPtr.Zero;
                Check(NativeMethods.CryptAcquireCertificatePrivateKey(
                    certContext,
                    0,
                    IntPtr.Zero,
                    out providerContext,
                    out keySpec,
                    out callerFreeProvOrNCryptKey));
                // 不要になったハンドルを解放
//.........这里部分代码省略.........
开发者ID:UrmnafBortHyuga,项目名称:csharplesson,代码行数:101,代码来源:Certificate.cs

示例10: Update

	// Update is called once per frame
	void Update () {

        // 投影
        if (projection_flag)
        {

            // off-screen rendering
            //var camtex = RenderTexture.GetTemporary(proWidth, proHeight, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
            //myProjector.targetTexture = camtex;
            //myProjector.Render();
            //RenderTexture.active = camtex;

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

            RenderTexture.active = ProjectorImage;
            tex.ReadPixels(new Rect(0, 0, ProjectorImage.width, ProjectorImage.height), 0, 0);
            tex.Apply();

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

            //投影するとゆがむので、(逆方向に)歪ませる
            undistort(texturePixelsPtr_, texturePixelsPtr_, proWidth, proHeight, procamManager.proj_K, procamManager.proj_dist);

            // Show a window
            fullWindow(windowName, displayNum, texturePixelsPtr_, proWidth, proHeight);
            //drawTextureFullWindow(window_, texturePixelsPtr_);

            texturePixelsHandle_.Free();

            //影画像のレンダリング
            Graphics.Blit(ProjectorImage, shadowImage, shadowMat);

            //RenderTexture.active = null;
            //RenderTexture.ReleaseTemporary(camtex);
            //myProjector.targetTexture = null;

            RenderTexture.active = null;
        }
	}
开发者ID:kurepasu0731,项目名称:ProjectingLight,代码行数:44,代码来源:ProjectionWindow.cs

示例11: projectorCalibration


//.........这里部分代码省略.........
                // 投影終了
                calib_flag = false;

                closeWindow(graycodeWindow);
                closeWindow(checkWindow);
                print("グレイコード投影終了");

                make_thresh(proWidth, proHeight, camWidth, camHeight);
                print("2値化終了");

                int[] proPointx = new int[proWidth * proHeight];
                int[] proPointy = new int[proWidth * proHeight];
                int[] camPointx = new int[proWidth * proHeight];
                int[] camPointy = new int[proWidth * proHeight];
                int correspondNum = 0;
                makeCorrespondence(proWidth, proHeight, camWidth, camHeight, proPointx, proPointy, camPointx, camPointy, ref correspondNum);
                print("グレイコード終了");

                List<double> Point2dx = new List<double>();
                List<double> Point2dy = new List<double>();
                List<double> Point3dx = new List<double>();
                List<double> Point3dy = new List<double>();
                List<double> Point3dz = new List<double>();
                int correspoindNum2 = 0;

                // Kinectのカラー空間をカメラ空間へ変換
                calcColorPointToWorld(multiSourceManagerScript.GetDepthData(), multiSourceManagerScript.ColorWidth, multiSourceManagerScript.ColorHeight,
                                        camPointx, camPointy, proPointx, proPointy, correspondNum, ref Point2dx, ref Point2dy, ref Point3dx, ref Point3dy, ref Point3dz, ref correspoindNum2);

                double[] proPoint2dx = new double[correspoindNum2];
                double[] proPoint2dy = new double[correspoindNum2];
                double[] camPoint3dx = new double[correspoindNum2];
                double[] camPoint3dy = new double[correspoindNum2];
                double[] camPoint3dz = new double[correspoindNum2];
                proPoint2dx = Point2dx.ToArray();
                proPoint2dy = Point2dy.ToArray();
                camPoint3dx = Point3dx.ToArray();
                camPoint3dy = Point3dy.ToArray();
                camPoint3dz = Point3dz.ToArray();

                print("対応点数:"+correspoindNum2);

                double[] cameraMat = new double[16];
                double[] externalMat = new double[16];
                double result = 0;

                // プロジェクタキャリブレーション
                print("キャリブレーション実行");
                calcCalibration(proPoint2dx, proPoint2dy, camPoint3dx, camPoint3dy, camPoint3dz, correspoindNum2, proWidth, proHeight, cameraMat, externalMat, ref result);

                print("再投影誤差:"+result);

                // 透視投影変換行列を掛ける
                originalProjection.m00 = (float)cameraMat[0];
                originalProjection.m01 = (float)cameraMat[1];
                originalProjection.m02 = (float)cameraMat[2];
                originalProjection.m03 = (float)cameraMat[3];
                originalProjection.m10 = (float)cameraMat[4];
                originalProjection.m11 = (float)cameraMat[5];
                originalProjection.m12 = (float)cameraMat[6];
                originalProjection.m13 = (float)cameraMat[7];
                originalProjection.m20 = (float)cameraMat[8];
                originalProjection.m21 = (float)cameraMat[9];
                originalProjection.m22 = (float)cameraMat[10];
                originalProjection.m23 = (float)cameraMat[11];
                originalProjection.m30 = (float)cameraMat[12];
                originalProjection.m31 = (float)cameraMat[13];
                originalProjection.m32 = (float)cameraMat[14];
                originalProjection.m33 = (float)cameraMat[15];

                // set projection matrix
                myProjector.projectionMatrix = originalProjection;

                originalExternal.m00 = (float)externalMat[0];
                originalExternal.m01 = (float)externalMat[1];
                originalExternal.m02 = (float)externalMat[2];
                originalExternal.m03 = (float)externalMat[3];
                originalExternal.m10 = (float)externalMat[4];
                originalExternal.m11 = (float)externalMat[5];
                originalExternal.m12 = (float)externalMat[6];
                originalExternal.m13 = (float)externalMat[7];
                originalExternal.m20 = (float)externalMat[8];
                originalExternal.m21 = (float)externalMat[9];
                originalExternal.m22 = (float)externalMat[10];
                originalExternal.m23 = (float)externalMat[11];
                originalExternal.m30 = (float)externalMat[12];
                originalExternal.m31 = (float)externalMat[13];
                originalExternal.m32 = (float)externalMat[14];
                originalExternal.m33 = (float)externalMat[15];

                // set external matrix
                myProjector.worldToCameraMatrix = originalExternal;

                posi_count = 0;
                nega_count = 0;
            }
        }

        texturePixelsHandle_.Free();
    }
开发者ID:kurepasu0731,项目名称:ProjectionMapping,代码行数:101,代码来源:ProjectorCalibration.cs


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