High memory usage with madExcept

delphi package - automated exception handling

High memory usage with madExcept

Postby csamartin » Mon Nov 21, 2016 3:33 pm

In a large Delphi 7 project (consists of > 20 DLLs + Exe; uses COM/ActiveX) I observe a big difference (> 500MB) in memory usage if i compile the binaries with or without madExcept.

See Image below.

This causes OutOfMemory Exceptions quite often, since the DLLs are sometimes linked into a .NET environment via COM and the host application is quite memory consuming itself.I also use FastMM. Without madExcept no problem occurrs.

Does anybody have observed similar problems and/or has a solution?
Attachments
MemoryUsage.png
MemoryUsage.png (23.57 KiB) Viewed 574 times
csamartin
 
Posts: 3
Joined: Mon Nov 21, 2016 3:09 pm

Re: High memory usage with madExcept

Postby madshi » Mon Nov 21, 2016 3:57 pm

Did you accidently activate the "leak reporting" or "crash on buffer overrun/underrun" features? These consume a lot more RAM.
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Re: High memory usage with madExcept

Postby csamartin » Tue Nov 22, 2016 1:20 pm

No they are both off.

But the options 'RangeChecks', 'IOChecks' and 'OverFlowChecks' are activated.
Could that possibly have an effect?
csamartin
 
Posts: 3
Joined: Mon Nov 21, 2016 3:09 pm

Re: High memory usage with madExcept

Postby madshi » Tue Nov 22, 2016 1:47 pm

No, that shouldn't make any difference.

Wait, are all those > 20 DLLs compiled with madExcept? madExcept allocates a "dummy" block of about 18MB in its initialization, which is always freed whenever an exception is raised, and then allocated again after exception handling has completed. The purpose of this behaviour is that this memory block is supposed to ensure that even if the process is running out of RAM, madExcept still has some headroom to do its job. Normally, 18MB is not a problem at all. But if you have 20+ DLLs, and if they're all compiled with the full blown madExcept logic, each of them will allocate 18MB which of course adds up to a lot of RAM overall. Would that explain the problem?
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Re: High memory usage with madExcept

Postby madshi » Tue Nov 22, 2016 1:48 pm

P.S: Most of those 18MB are only *reserved*, not allocated, but they still block a part of the addressable memory range, which in 32bit is limited to 4GB.
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Re: High memory usage with madExcept

Postby csamartin » Tue Nov 22, 2016 3:24 pm

Thank's a lot - that's probably the explanation.
I've counted almost thirty Modules (Exe+DLLs) loaded simultanously at run time, which add up to 30 * 18MB = 540MB.

Is there a constant in the madExcept source code (which I use for compiling the binaries) defining the "18MB".
In other words, is it possible to reduce this size? Or would you recommend against it?
csamartin
 
Posts: 3
Joined: Mon Nov 21, 2016 3:09 pm

Re: High memory usage with madExcept

Postby madshi » Tue Nov 22, 2016 3:32 pm

It's just a safety net against problems for "out of RAM" situations. For any other situations these 18MB are useless. So I see no big problem reducing that at all.

Please look at madExcept.AllocOutOfMemoryInsurance(). Feel free to change that to whatever values you're comfortable with. There are 2 VirtualAlloc calls there: One that reserves (but doesn't allocate) a big chunk of memory (4MB), the other one truely allocates 500KB. This is done 4 times, which sumes up to 18MB.
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 4 guests