Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-25-2001, 07:21 AM
einform einform is offline
Junior Member
 
Join Date: Feb 2001
Posts: 18
Default Detecting GUI resources

I have an app which could well consume 100% GUI resources - something I wish to avoid, hence does anyone know any tricks to keep an eye on this and at a certain percentage level (ie say 90% full) I could trigger an event to free things up a little.

Any help appreciated.

Nev
Reply With Quote
  #2  
Old 04-25-2001, 11:38 PM
Verence Verence is offline
Senior Member
 
Join Date: Feb 2001
Posts: 435
Default RE: Detecting GUI resources

Hi!

Getting Resources, not very easy, it need to 'thunk' a 16 bit DLL and it doesn't word under NT at all!

type
TLoadLibrary16 = function (LibraryName: PChar): THandle; stdcall;
TFreeLibrary16 = procedure (HInstance: THandle); stdcall;
TGetProcAddress16 = function (Hinstance: THandle; ProcName: PChar): Pointer; stdcall;
TQT_Thunk = procedure; cdecl;

var
_LoadLibrary16 :TLoadLibrary16;
_FreeLibrary16 :TFreeLibrary16;
_GetProcAddress16 :TGetProcAddress16;
_QT_Thunk :TQT_Thunk;
hInst16: THandle;
HKernel :Thandle;

procedure QT_Thunk;
begin
if assigned(_QT_Thunk) then
_QT_Thunk;
end;

function GetFreeSysRes(SysRes: Word): Word;
var
SR: Pointer;
idxLoadLibrary16,
idxFreeLibrary16,
idxGetProcAddress16 :dword;
begin
result:=0;
HKernel:=GetModuleHandle('kernel32.dll');
idxLoadLibrary16:=35;
idxFreeLibrary16:=36;
idxGetProcAddress16:=37;
if HKernel<>0 then begin
@_LoadLibrary16:=getprocaddress(HKernel,@idxLoadLi brary16);
@_FreeLibrary16:=getprocaddress(HKernel,@idxFreeLi brary16);
@_GetProcAddress16:=getprocaddress(HKernel,@idxGet ProcAddress16);
@_QT_Thunk:=getprocaddress(HKernel,pchar('QT_Thunk '));
end
else begin
//raise Exception.Create('Kernel32.DLL unloadable');
exit;
end;

hInst16:=0;
if assigned(_LoadLibrary16) then begin
hInst16:=_LoadLibrary16('user.exe')
end;

if hInst16>32 then begin
if assigned(_FreeLibrary16) then begin
_FreeLibrary16(HInstance);
end;
SR:=nil;
if assigned(_GetProcAddress16) then begin
SR:=_GetProcAddress16(hInst16,'GetFreeSystemResour ces');
end;
if assigned(SR) then begin
asm
push SysRes // push arguments
mov edx, SR // load 16-bit procedure pointer
call QT_Thunk // call thunk
mov Result, ax // save the result
end
end
else begin
//raise Exception.Create('GetFreeSystemResources - address not found');
end;
end
else begin
//raise Exception.Create('USER.EXE unloadable');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
GetFreeSysRes(1);
end;

------
So, better try to keep the memory consumption of your application as low as possible:
- Free any unused resource / form / object etc.
- create Form only when needed, not with the program start
- use Conponents that don't need window handles eg tLabel instaed of tPanel or tStaticText
- try to avoid PageControls or call Dormant for the invisible pages
- use a profiling tool (eg. MemProof) to check where you need lot of resources

It's usually better to avoid the problem than to react when it occurs.




HTH )
Verence
Reply With Quote
  #3  
Old 04-26-2001, 02:11 AM
einform einform is offline
Junior Member
 
Join Date: Feb 2001
Posts: 18
Default RE: RE: Detecting GUI resources

Thanks Verence

Your right, I've gone about as far as I can to make sure my app has a minimum foot print but a user may load up one of my PlusMemo components with a massive amount of text, hence the potential problem.

Once again thanks for the hints+code - great!

regards

Nev
Reply With Quote
  #4  
Old 04-27-2001, 12:30 AM
Verence Verence is offline
Senior Member
 
Join Date: Feb 2001
Posts: 435
Default RE: RE: RE: Detecting GUI resources

Hi Nev!

Just one more thought:
I don't know about your PlusMemo component, but if it's only text that is loaded you should get no problem with the GUI resources, only with the 'normal' memory. If this is true it could be helpfull to increase the size of the virtual memory (see Windows System Control) or to check the size of the remaining memory (lookup TMemoryStatus in Delphi help)

PS: if the PlusMemo decends form TMemo, IMHO it is limited to 64Kb of text under Win95/98...

HTH )
Verence
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:25 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.