Board index » delphi » How to reduce memory usage?

How to reduce memory usage?

Almost all my apps use about 4000Ko of memory, and i don't know how to make
them use less. I'm builing a background application, and it cannot be
usefull if it uses 4megs.
Any suggestion?
 

Re:How to reduce memory usage?


Well, you could describe your app

4mb seems a bit large - perhaps you are doing something daft

The 'Almost all' bit suggests that you are using something in common
throughout your Apps - could it be something like:- MEMHOG.OCX

Occam's razor is the (most appropriate) solution.

On Fri, 21 Dec 2001 16:08:25 +0100, "AntoineHotmail"

Quote
<antoine...@hotmail.com> wrote:
>Almost all my apps use about 4000Ko of memory, and i don't know how to make
>them use less. I'm builing a background application, and it cannot be
>usefull if it uses 4megs.
>Any suggestion?

Re:How to reduce memory usage?


Ok, 4 is exagerated, let's say three and a half.
For example, one is a database i use to manage the CD I burn, and another is
a PPPoE-autodialer.
There's not much code because i'm still a beginner, and i don't know how to
optimize this code.
And the thing i use in common for all apps is (only) Delphi6. I write with
it and i compile with it.
The exe is a stand alone. I thought about building a Dll, but there are only
3 or 4 procedures i would only put in it.

@+
Antoine

"J French" <je...@iss.u-net.com> a crit dans le message de news:
3c236262.641...@news.u-net.com...

Quote
> Well, you could describe your app

> 4mb seems a bit large - perhaps you are doing something daft

> The 'Almost all' bit suggests that you are using something in common
> throughout your Apps - could it be something like:- MEMHOG.OCX

> Occam's razor is the (most appropriate) solution.

> On Fri, 21 Dec 2001 16:08:25 +0100, "AntoineHotmail"
> <antoine...@hotmail.com> wrote:

> >Almost all my apps use about 4000Ko of memory, and i don't know how to
make
> >them use less. I'm builing a background application, and it cannot be
> >usefull if it uses 4megs.
> >Any suggestion?

Re:How to reduce memory usage?


Quote
"AntoineHotmail" <antoine...@hotmail.com> wrote in message

news:9vvjdv$sev$1@wanadoo.fr...

Quote
> Almost all my apps use about 4000Ko of memory, and i don't know how to
make
> them use less. I'm builing a background application, and it cannot be
> usefull if it uses 4megs.
> Any suggestion?

A typical machine these days has close to 1GB of (virtual) memory. I
wouldn't worry about an application using 0.4% of any resource.

Re:How to reduce memory usage?


Quote
"AntoineHotmail" <antoine...@hotmail.com> wrote in message

news:9vvjdv$sev$1@wanadoo.fr...

Quote
> Almost all my apps use about 4000Ko of memory, and i don't know how to
make
> them use less. I'm builing a background application, and it cannot be
> usefull if it uses 4megs.
> Any suggestion?

Measured how?

How much is actually committed memory and how much reserved?
How much can actually be swapped out?
How much is DLL.
You are probably really using 600K and most of that can be swapped out,
the 2mdata/2mcode is normal allocation for Delphi.

Reserved virtual memory and heap is not necessarily assigned to ram/hd
space.
DLLs are mapped into multiple processes

See Win32 VirtualQuery and MEMORY_BASIC_INFORMATION  structure

Decreasing the reported memory use is only cosmetic

depending on what libraries you need you could add this code to the dpr
reduces 4.5M reported actually using 900k most  swappable
to 2.2M reported actually using 600k

there are many other ways but they are mostly cosmetic, are a lot of effort
,
mangle the code, and save a cent or two of HD space
 ..provided the app can be swapped when needed that is all a few meg of
virtual memory costs.

Now, if only the users would understand :-( Perhaps you could document
why it is so huge and price it at $19.98 instead of $20 ? ;-)

var b:boolean;
var H:Thandle;
begin
    h:=getmodulehandle('OLEAUT32.DLL');  // loaded automatically in init
    b:=freelibrary(h);
    h:=getmodulehandle('OLE32.DLL');
    b:=freelibrary(h);
{    h:=getmodulehandle('COMDLG32.DLL');
    b:=freelibrary(h);
    h:=getmodulehandle('ADVAPI32.DLL');
    b:=freelibrary(h);
    h:=getmodulehandle('SHELL32.DLL');
    b:=freelibrary(h);
    h:=getmodulehandle('SHLWAPI.DLL');
    b:=freelibrary(h);}
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
  loadlibrary('OLEAUT32.DLL');  // put back ..otherwise crash on exit
end.

Re:How to reduce memory usage?


Quote
"J French" <je...@iss.u-net.com> wrote in message

news:3c236262.641359@news.u-net.com...

Quote
> Well, you could describe your app

> 4mb seems a bit large - perhaps you are doing something daft

> The 'Almost all' bit suggests that you are using something in common
> throughout your Apps - could it be something like:- MEMHOG.OCX

*runs a scan for MEMHOG.OCX*

... whoah.. Its there!  DAMN YOU MICROSOFT!

Quote

> Occam's razor is the (most appropriate) solution.

> On Fri, 21 Dec 2001 16:08:25 +0100, "AntoineHotmail"
> <antoine...@hotmail.com> wrote:

> >Almost all my apps use about 4000Ko of memory, and i don't know how to
make
> >them use less. I'm builing a background application, and it cannot be
> >usefull if it uses 4megs.
> >Any suggestion?

I don't mean to sound like I'm belittling you, but, are you looking at your
EXE file size, or actual memory use?  4Meg for an EXE is extremly excessive
even for an EXE though.

What variables are you declaring?  Do you have Built-In Debugging turned on?

Re:How to reduce memory usage?


Quote
"Stephen" <idontk...@somewhere.asdf> wrote in message news:2LOU7.34565
> I don't mean to sound like I'm belittling you, but, are you looking at
your
> EXE file size, or actual memory use?  4Meg for an EXE is extremly
excessive
> even for an EXE though.

4MB exe size is nothing. It certainly isn't excessive. Win doesn't load the
entire exe on start-up. More over, if one wants to write a good looking GUI,
much of an exe is going to be taken up with data for the interface.

Re:How to reduce memory usage?


your right that 4 meg isn't much. The people I started work for recently
have 2 products that are about 8 and 11 meg, and they use an old DOS style
interface :)

--
~~~~~~~~~~~~~
?raig ?eynolds
~~~~~~~~~~~~~
Just because this is never going to work is no reason to be negative!

Quote
"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message

news:9QRU7.6486$Q06.37122@tor-nn1.netcom.ca...
Quote

> "Stephen" <idontk...@somewhere.asdf> wrote in message news:2LOU7.34565

> > I don't mean to sound like I'm belittling you, but, are you looking at
> your
> > EXE file size, or actual memory use?  4Meg for an EXE is extremly
> excessive
> > even for an EXE though.

> 4MB exe size is nothing. It certainly isn't excessive. Win doesn't load
the
> entire exe on start-up. More over, if one wants to write a good looking
GUI,
> much of an exe is going to be taken up with data for the interface.

Re:How to reduce memory usage?


In article <9vvjdv$se...@wanadoo.fr>, antoine...@hotmail.com says...

Quote
> Almost all my apps use about 4000Ko of memory, and i don't know how to make
> them use less. I'm builing a background application, and it cannot be
> usefull if it uses 4megs.
> Any suggestion?

Are you using exessive number of third-party components?
Some people has bad habbit of adding components that does some functions
that otherwise could be written in 20 lines of code without it...
Then, experimenting with many components and deleting them, whoithout
checking if they are really cleared from USES list...

--
Best regards,
Emil Beli
http://www.greenhousemm.com

Re:How to reduce memory usage?


"Craig Reynolds" <reynoldscra...@hotmail.com> skrev i melding
news:3c2403b6$0$30887@echo-01.iinet.net.au...

Quote
> your right that 4 meg isn't much. The people I started work for recently
> have 2 products that are about 8 and 11 meg, and they use an old DOS style
> interface :)

You guys have to be really generous with graphic decorations in your apps. My
record so far is 1.8 MB, and then I'd been putting stuff into it for
months...it even has a large splash screen image...;-)

But - to the original question: What Windows reports isn't necessarily
correct. It may have been using memory (or even just reserving for possible
use) for a moment that was freed up but still reported as belonging to the
application. Right ? ISTM that NT reports a much larger memory usage figure
than Win9x.
--
Bjoerge Saether
Asker, Norway
bjorge@hahaha_itte.no (remve the obvious)

Re:How to reduce memory usage?


I'm not sure about NT reporting a larger figure than 9x, I don't recall ever
hearing that, but that doesn't mean much. As for being generous with
graphics for the apps, not really. I imagine the size comes from the fact
that they both have more than 2 million lines of code in them.

--
~~~~~~~~~~~~~
?raig ?eynolds
~~~~~~~~~~~~~
Just because this is never going to work is no reason to be negative!

Quote
"Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> wrote in message

news:CZ_U7.7477$KQ3.91090@news1.oke.nextra.no...
Quote
> "Craig Reynolds" <reynoldscra...@hotmail.com> skrev i melding
> news:3c2403b6$0$30887@echo-01.iinet.net.au...
> > your right that 4 meg isn't much. The people I started work for recently
> > have 2 products that are about 8 and 11 meg, and they use an old DOS
style
> > interface :)

> You guys have to be really generous with graphic decorations in your apps.
My
> record so far is 1.8 MB, and then I'd been putting stuff into it for
> months...it even has a large splash screen image...;-)

> But - to the original question: What Windows reports isn't necessarily
> correct. It may have been using memory (or even just reserving for
possible
> use) for a moment that was freed up but still reported as belonging to the
> application. Right ? ISTM that NT reports a much larger memory usage
figure
> than Win9x.
> --
> Bjoerge Saether
> Asker, Norway
> bjorge@hahaha_itte.no (remve the obvious)

Re:How to reduce memory usage?


Quote
"Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> wrote in message

news:CZ_U7.7477$KQ3.91090@news1.oke.nextra.no...

Quote
> "Craig Reynolds" <reynoldscra...@hotmail.com> skrev i melding
> news:3c2403b6$0$30887@echo-01.iinet.net.au...
> > your right that 4 meg isn't much. The people I started work for recently
> > have 2 products that are about 8 and 11 meg, and they use an old DOS
style
> > interface :)

> You guys have to be really generous with graphic decorations in your apps.
My
> record so far is 1.8 MB, and then I'd been putting stuff into it for
> months...it even has a large splash screen image...;-)

I've got two commercial products.  One just for inhouse, the other for
public availability.  The first version of the software was developed under
VB, and its code, including the OCXs and everything else it deemed necessary
(All I was using was strictly basic commands, and basic components.  Nothing
like storing BMPs) for a small app, I couldn't fit it on a simple floppy
disk.  Under D3 (At the time thats what I was using) I compiled, and managed
to nail under 100K.  My record for my comercial product is 1.6meg in size.
And for what this program is doing, it does a LOT.

Quote

> But - to the original question: What Windows reports isn't necessarily
> correct. It may have been using memory (or even just reserving for
possible
> use) for a moment that was freed up but still reported as belonging to the
> application. Right ? ISTM that NT reports a much larger memory usage
figure
> than Win9x.

This sounds rather stupid, and uneducated, but, by small chance, would the
OS of any style keep that memory available to the program short term?  Under
9x/NT, we don't have direct access to memory (Can't poke at $b800:0000
directly to change the top left character on a colour monitor anymore.
*sigh*)  So, maybe as part of efficiceny as far as memory management goes,
it keeps that segment of memory available to the app, just incase it needs
more?  Sounds dumb, but, who knows. <grin>
Quote
> --
> Bjoerge Saether
> Asker, Norway
> bjorge@hahaha_itte.no (remve the obvious)

Re:How to reduce memory usage?


"Memory" is all virtual anyway, and it's often over-stated depending on
exactly how it is calculated.

What matters is how much memory is in your active "working set" while
the program is running:  that's the amount of memory the program has
used recently, and that's also the [only] amount of real memory that
Windows has allocated to it.  (This number changes from time to time...
and even then, Windows doesn't try too hard to "squeeze" that number
unless the system begins to run short.)

It also matters how much "swapping" the program generates while the
system is under load.  If the program dances around its memory space,
hitting new pages constantly, it will present a bigger "footprint" to
the system.

Again...  Windows doesn't care much how large your _virtual memory
request is (it sometimes _defaults to 4M with Delphi programs)...  and
it doesn't even try to squeeze the working-set size unless it has to.
["If you got it, flaunt it."]

Quote
>AntoineHotmail wrote:

> Almost all my apps use about 4000Ko of memory, and i don't know how to make
> them use less. I'm builing a background application, and it cannot be
> usefull if it uses 4megs.
> Any suggestion?

----------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)
Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  Release 4.0 is here!!
> http://www.sundialservices.com/products/chimneysweep

Re:How to reduce memory usage?


"Craig Reynolds" <reynoldscra...@hotmail.com> skrev i melding
news:3c24a519$0$30889@echo-01.iinet.net.au...

Quote
> I'm not sure about NT reporting a larger figure than 9x, I don't recall
ever
> hearing that, but that doesn't mean much. As for being generous with
> graphics for the apps, not really. I imagine the size comes from the fact
> that they both have more than 2 million lines of code in them.

I've never seen much more than 200,000 lines compiled upon a 'build all'...I
believe that explains the difference ;-)

Quote
> ~~~~~~~~~~~~~
> ?raig ?eynolds
> ~~~~~~~~~~~~~
> Just because this is never going to work is no reason to be negative!
> "Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> wrote in message
> news:CZ_U7.7477$KQ3.91090@news1.oke.nextra.no...
> > "Craig Reynolds" <reynoldscra...@hotmail.com> skrev i melding
> > news:3c2403b6$0$30887@echo-01.iinet.net.au...
> > > your right that 4 meg isn't much. The people I started work for
recently
> > > have 2 products that are about 8 and 11 meg, and they use an old DOS
> style
> > > interface :)

> > You guys have to be really generous with graphic decorations in your
apps.
> My
> > record so far is 1.8 MB, and then I'd been putting stuff into it for
> > months...it even has a large splash screen image...;-)

> > But - to the original question: What Windows reports isn't necessarily
> > correct. It may have been using memory (or even just reserving for
> possible
> > use) for a moment that was freed up but still reported as belonging to
the
> > application. Right ? ISTM that NT reports a much larger memory usage
> figure
> > than Win9x.
> > --
> > Bjoerge Saether
> > Asker, Norway
> > bjorge@hahaha_itte.no (remve the obvious)

--
Bjoerge Saether
Asker, Norway
bjorge@hahaha_itte.no (remve the obvious)

Re:How to reduce memory usage?


Wow, this is too much for me. I'm just a beginner...
When i talk about memory usage, it's what i see with the task manager of
windows (XP)
My exe is just about 500 Ko on hardisk, and there's not that much variables.
But in fact, i've let my app on for a long time, and seems that it uses less
and less memory. After about 4 hours of running, it just uses 392 ko (always
with task manager).
Thanks to all for your answers.
Go to page: [1] [2]

Other Threads