调用代码如下:
type
  TIntFunc1 = function(i: integer): integer; stdcall;
  TIntFunc2 = function(i, j: integer): TPoint; stdcall;
var
  Th: Thandle;
  Tf1: TIntFunc1;
  Tf2: TIntFunc2;
  Tp: TFarProc;
  i, j: integer;
begin  Th := LoadLibrary('RData.dll'); {装载DLL}
  if Th > 0 then
  try
    Tp := GetProcAddress(Th, PChar('datalen'));
    if Tp <> nil then
    begin
      Tf1 := TIntFunc1(Tp);
      for i := 1 to 3 do setlength(tpointdata[i], datalen(i));
    end
    else ShowMessage('datalan not found,err#');    Tp := GetProcAddress(Th, PChar('SendData'));
    if Tp <> nil then
    begin
      Tf2 := TIntFunc2(Tp);      for i := 1 to 3 do
        for j := 0 to length(tpointdata[i]) - 1 do
          tpointdata[i][j] := SendData(i, j);
    end
    else ShowMessage('Senddata not found,err#');  finally
    FreeLibrary(Th); {释放DLL}
  end else ShowMessage('RData.dll没有找到');
end;有什么好办法查找释放内存了没有,感觉是没有释放内存,程序运行所占内存反而比静态调用要大请指点首次发,不知道如何给分

解决方案 »

  1.   

    本段程序共有两个功能:取数组长度
    dll发送这个长度的数据如果有什么好的办法,或者问题,请说明,谢谢
      

  2.   

    调用了FreeLibrary后就已经释放掉了,如果出现内存泄露问题也是你得dll有问题
      

  3.   

    谢谢,这么快就有回复,dll只调用这一次,而且马上释放,何来泄露这事呢?再帖 dll:library RData;
    uses
      SysUtils, windows,
      Classes;var
      tpointdata: array[1..3] of array of Tpoint;
      data: array[1..64 * 1024] of word;
      exitpoint:pointer;function datalen(i: integer): integer; stdcall;
    begin
      result := length(tpointdata[i]);
    end;function SendData(i, j: integer): Tpoint; stdcall;
    begin
      result := tpointdata[i][j];
    end;procedure DataRead;
    var fs: tfilestream;
    begin
      fs := tfilestream.Create('abc', fmOpenRead);
      fs.READBuffer(data, 128 * 1024); ////////////////////
      fs.Free;
    end;procedure DataConverToPoint;
    var
    ....
    procedure libexit;
    begin
    exitproc:=exitpoint;
    end;
    procedure MyDLL(Reason: integer); far; stdcall;
    begin
    exitpoint:=exitproc;
    exitproc:=@libexit;
      case reason of    dll_process_attach:
          begin
            DataRead;
            DataConverToPoint;
          end;
        dll_process_detach:
          ;
        dll_thread_attach: ;
        dll_thread_detach:
          ;
      end;
    end;{$R *.res}
    exports
      SendData,
      datalen;
    begin  DLLProc := @MyDLL;
      MyDLL(dll_process_attach);
    end.
    头一次写,中间省略的地方是一些运算和对tpointdata[][] 敷值,代码多。
      

  4.   

    简单的测试,多次Laod+Free,如果内存不断增加,才有泄漏,如果保持在一个阶段不变,就是正常的另外,DELPHI写的DLL有内存泄漏,参见
    http://community.csdn.net/Expert/TopicView.asp?id=5452414
      

  5.   

    好主意,
    刚才把那段 调用和释放代码运行了10000次花销 110秒,任务管理器中内存始终是5676k不变,
    释放返回值也对,可就不知道为什么,要比静态调用占用内存大
    是不是定义有问题:{$R *.dfm}
    function datalen(i: integer): integer; stdcall; external 'RData.dll';
    function SendData(i, j: integer): TPoint; stdcall; external 'RData.dll';如果没人解答这个问题暂时就不纠緾了。有人解答就当然就更好了想找人帮助研究一下代码,可量写程序的人要价都不低。
    如果有闲着没事干的程序员我们一起研究就好了
      

  6.   

    任务管理器中 没有 出现 RData.dll我怀疑不是动态加载!有什么办法呢?
      

  7.   

    楼上的两个带星的纯粹是在放屁。好久不来了.....Dll如果帮助host创建了堆上存储的数据,即使FreeLibrary后内存同样不会释放。CSDN的这些星星们水平也忒次了点了吧
      

  8.   

    哈哈,太高深了
    用和不用freelibrary,我看dll没有优势,无论在内存使用量,还是速度上。
    另外任务管理器上也不反映出来.其实我知道肯定有区别,只是不知道在哪里?当然目前也不必要知道太难的
    我现在在到处抄代码,想到哪里就google和摆渡到哪里,程序属于0起点。我这水平,和他们的差距,估计在这里永远混不上星星了