SetProcessWorkingSetSize

From: Chris Buys (chris_at_h-a-s.co.za)
Date: 10/13/03


Date: Mon, 13 Oct 2003 17:22:20 +0200

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


Relevant Pages

  • Re: Why do we need executables in certain formats ?
    ... > complex binary formats was that programs need to be relocated, ... > perhaps linked with libraries. ... Modern virtual memory processors can locate to ... > has a hidden problem with the new .DLL. ...
    (comp.lang.asm.x86)
  • Re: Why is Base3.exe using 700+ K in windows task manager ?
    ... DLL function. ... handles opened by any thread of the calling process ... The DLL allocates memory from the virtual address space of the calling ... Who can tell where memory is really located in a virtual adress space? ...
    (alt.lang.asm)
  • Re: shared DLL VS static Link, Are they different?
    ... MFC exits, and if there is any memory that is freed at that time, MFC will ... business dumping leaks; it should wait until the CRT DLL dumps leaks after ... ALL RESOURCES OWNED BY THAT PROCESS ARE RELEASED. ...
    (microsoft.public.vc.mfc)
  • Re: Linking to a .NET dll from C#
    ... for obtaining price quotes and performance is absolutely critical. ... be to use shared memory or memory mapped files. ... Be aware that in these scenarios you're responsible for patching and updates, as the application will no longer rely on the clients machine to keep the framework up to date. ... Determine if a certain managed .NET dll or assembly is loaded ...
    (microsoft.public.dotnet.general)
  • Re: Where did my VB function go?
    ... If the VB application loads the C++ DLL, the DLL gets ... And there is a very common error with shared memory, ... A DLL has a shared memory section. ... series of coherent linked lists local to each attached process. ...
    (microsoft.public.vb.winapi)