Article View: borland.public.cppbuilder.nativeapi
Article #13453SetProcessWorkingSetSize
From: Chris Buys
Date: Mon, 13 Oct 2003 15:22
Date: Mon, 13 Oct 2003 15:22
67 lines
2943 bytes
2943 bytes
Hi everybody!
I'm having difficulties with setting the working set size of a process.
Here is the scenario:
A normal application loads a DLL dynamically and one of the calling
arguments
is the application's handle: Application->Handle (the app was written in
BCB5).
This goes fine over into the Delphi 5 DLL. ShowMessage-ing shows the same
number
inside the DLL.
Unfortunately the work the DLL does eats up memory like there's no tomorrow.
In the Win2000 TaskManager the memory usage for that process keeps going up
and after 30 min to 1 hour Win2000 runs out of page memory and throws an
error.
So I want to keep the working set of the memory down to sane levels with the
SetProcessWorkingSetSize API call.
Here is my code for the above action:
//--------------------------------------------------------------------------
----
procedure SetMemoryData(P : HWND; ceiling : Cardinal);
var
min, max, error : Cardinal;
begin
try
GetProcessWorkingSetSize(P,min,max);
if (Trunc((min + max) / 2) > ceiling) then
begin
if (SetProcessWorkingSetSize(P,1048576,2097152) = false) then
begin
error := GetLastError;
ShowMessage('error on setting size');
ShowMessage(IntToStr(error));
end;
end;
except on e:Exception do
ShowMessage(e.Message+' GetMemoryData');
end;
end;
//--------------------------------------------------------------------------
----
When the variables "min" and "max" are inspected after the Get-procedure,
their
values are zero (0). Just before the function is called the first time a
Get is done as
well and it returns non-zero data. Why? The same Handle (P) is used in
each instance!
I've already checked the DLL's code for any possible memory leaks, but could
not determine any. Any ideas?
Thank you in advance.
Chris
--------------------------------------
Chris Buys
Development
HAS Software (Pty) Ltd
Technical Details
Message-ID:
<3f8ac433@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,656eae8ed23df311,start X-Google-Attributes: gid10cc67,public X-Google-Thread: f94dd,656eae8ed23df311,start X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2003-10-13 08:31:58 PST From: "Chris Buys" <chris@h-a-s.co.za> Newsgroups: borland.public.cppbuilder.nativeapi,borland.public.delphi.nativeapi Subject: SetProcessWorkingSetSize Date: Mon, 13 Oct 2003 17:22:20 +0200 Lines: 69 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 168.209.28.202 Message-ID: <3f8ac433@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1066058803 168.209.28.202 (13 Oct 2003 08:26:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail