BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PChar and strings = memory leaks??

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Katlim Ruiz
Guest





PostPosted: Fri Jan 02, 2004 5:05 pm    Post subject: PChar and strings = memory leaks?? Reply with quote



Hello

I have an application that has to run 24/7. And right now i'm getting
an increase in the memory usage really small but, in the end, it
forces the computer to be rebooted.

I have tested the application thoroughly and used several memory leaks
software and libraries and no leak was detected EXCEPT several
AnsiString messages. I really dont know why could this happen.

My only guess is this one:

In my application i have a C++ dll which is linked statically to the
Delphi application. The import of the method is like

function mydll_func(Param1: PChar; Param2: integer; var Param3:
PChar);

But when i call it, i always do a casting from string to Pchar

var A: string;
B: integer;
C: PChar;

mydll_func(PChar(A), B, C);

Can this casting be the cause of memory leaks?

Thanks in advance
KATLIM RUIZ
Back to top
Jay Freeman
Guest





PostPosted: Fri Jan 16, 2004 10:28 am    Post subject: Re: PChar and strings = memory leaks?? Reply with quote



Not really as you are only casting the string.

Have you tried calling the dll dynamicly??

Here is a function you could try and use.
The procedure takes in the name of the Dll and the function/procedure

CallDll(PChar('DllName'), 'mydll_func');

Unit1;
....
type
FMyProcedure = procedure(
var Param1: PChar;
var Param2: Integer;
var Param3: PChar;
)stdcall;
var
Form1: TForm;
ParamA:String;
ParamB:Integer;
ParamC:PChar;
....
Implimentation

procedure TForm1.CallDll(ADll, AFunction: PChar);
var
Hinst: THandle;
FPointer: TFarProc;
CallProcedure: FMyProcedure;
begin
Hinst := LoadLibrary(PChar(ADll));
try
try
if Hinst > 32 then
begin
FPointer := GetProcAddress(Hinst, AFunction);
if FPointer <> nil then
begin
if AFunction = 'mydll_func' then
begin
CallProcedure := FMyProcedure(FPointer);
CallProcedure(PChar(ParamA), ParamB, ParamC);

end
end
else
ShowMessage('DLL Function ' + AFunction + ' Not found');
end
else
ShowMessage('Dynamic Link Library not found');
except
MessageDlg('An unexpected error happend.', mtError, [mbOK], 0);
end;
finally
FreeLibrary(Hinst);
end;
end;

At least this way you are iliminating the C dll causing the problem by
freeing it after each time it is called.

Jay.


[email]kruiz (AT) tss (DOT) com.pe[/email] (Katlim Ruiz) wrote in message news:<6466881d.0401020905.559cb510 (AT) posting (DOT) google.com>...
Quote:
Hello

I have an application that has to run 24/7. And right now i'm getting
an increase in the memory usage really small but, in the end, it
forces the computer to be rebooted.

I have tested the application thoroughly and used several memory leaks
software and libraries and no leak was detected EXCEPT several
AnsiString messages. I really dont know why could this happen.

My only guess is this one:

In my application i have a C++ dll which is linked statically to the
Delphi application. The import of the method is like

function mydll_func(Param1: PChar; Param2: integer; var Param3:
PChar);

But when i call it, i always do a casting from string to Pchar

var A: string;
B: integer;
C: PChar;

mydll_func(PChar(A), B, C);

Can this casting be the cause of memory leaks?

Thanks in advance
KATLIM RUIZ

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.