zoukankan      html  css  js  c++  java
  • 非托管 调用非托管资源的使用

     调用非托管资源的使用

    一.了解:

    首先我们应该得了解什么是托管资源,什么又是非托管资源?带着问题去找答案,解决问题是不是就容易多了呢,接下来我们先来了解关于托管和非托管。

    不懂不怕,就怕不去研究,有啥不会找度娘,听说新度娘 Very beautiful的哦,想不想看看呢,想的就跟我走吧!(看右边相关人物-传说中的新度娘竟然是程序袁!)

    好了废话到此,是不是感觉好玩啊,不管做什么,当做玩,那么你会觉得很轻松。接下来进入正题:

    托管:

    托管资源(Managed Resource)是dot Net的一个概念,指那些资源的回收工作由.net CLRGC 机制自动完成,无需显式释放的资源。比如int,string,float,DateTime等等对象,要说的是.net中超过80%的资源都是托管资源

    非托管:

    对于这类资源虽然垃圾回收器(GC)可以跟踪封装非托管资源的对象的生存期,但它不了解具体如何清理这些资源。常见的非托管源有:
    ApplicationContext,Brush,Component,ComponentDesigner,Container,Context,Cursor,
    FileStream,Font,Icon,Image,Matrix,Object,OdbcDataReader,OleDBDataReader,Pen,
    Regex,Socket,StreamWriter,Timer,Tooltip 等。

    二.示例:

    调用ffmpeg的dll动态链接库:(入口如下)

     #region dllimport

            [UnmanagedFunctionPointer(CallingConvention.StdCall)]         public delegate int OnState(IntPtr ptr);

            [DllImport("wffmpeg64.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "WF_Transcode")]         public static extern int Transcode(ref _Context ctx, int async);

            [DllImport("wffmpeg64.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "WF_CreateThumbnail")]         public static extern int CreateThumbnail([MarshalAs(UnmanagedType.LPStr)]string filename, IntPtr ptr);

            [DllImport("wffmpeg64.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "WF_FreeIntptr")]         public static extern int Free(ref IntPtr ptr);

            #endregion

    由于类比较多,就不在这一一列举了。。。

                                                                                                                                                                             学习使人优越,优越于学习之中。

  • 相关阅读:
    Tensorflow学习笔记1
    强化学习——从最简单的开始入手
    MATLAB R2017a 安装与破解
    C# 理解lock
    Bayer Pattern
    OpenCV参考手册之Mat类详解
    opencv学习之颜色空间转换cvtColor()
    UNICODE下CString转string
    解决VS2013报错fopen、sprintf等函数安全的问题
    Convert between cv::Mat and QImage 两种图片类转换
  • 原文地址:https://www.cnblogs.com/zlp520/p/4499879.html
Copyright © 2011-2022 走看看