调用代码如下:
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;有什么好办法查找释放内存了没有,感觉是没有释放内存,程序运行所占内存反而比静态调用要大请指点首次发,不知道如何给分
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;有什么好办法查找释放内存了没有,感觉是没有释放内存,程序运行所占内存反而比静态调用要大请指点首次发,不知道如何给分
dll发送这个长度的数据如果有什么好的办法,或者问题,请说明,谢谢
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[][] 敷值,代码多。
http://community.csdn.net/Expert/TopicView.asp?id=5452414
刚才把那段 调用和释放代码运行了10000次花销 110秒,任务管理器中内存始终是5676k不变,
释放返回值也对,可就不知道为什么,要比静态调用占用内存大
是不是定义有问题:{$R *.dfm}
function datalen(i: integer): integer; stdcall; external 'RData.dll';
function SendData(i, j: integer): TPoint; stdcall; external 'RData.dll';如果没人解答这个问题暂时就不纠緾了。有人解答就当然就更好了想找人帮助研究一下代码,可量写程序的人要价都不低。
如果有闲着没事干的程序员我们一起研究就好了
用和不用freelibrary,我看dll没有优势,无论在内存使用量,还是速度上。
另外任务管理器上也不反映出来.其实我知道肯定有区别,只是不知道在哪里?当然目前也不必要知道太难的
我现在在到处抄代码,想到哪里就google和摆渡到哪里,程序属于0起点。我这水平,和他们的差距,估计在这里永远混不上星星了