• Welcome to Valhalla Legends Archive.
 

C++ Memory Use and Management

Started by LordVader, September 02, 2004, 10:23 AM

Previous topic - Next topic

LordVader

Curious to oppinions, when I first create a basic window program with nothing but the window and icon loaded into it. The residual memory it's using when executed is fairly high 2000 K+. I know in asm you can stream line the windows.inc file include by removing un-needed items as one example to reduce over all load and exe size..

Wondering if there are basic known equivelants to that in C++ (best practices basically) for includes and compile settings.

As well as ideas/theories on memory management in general on streamlining performance in applications when/where/method concepts..

Kp

From your description, you've configured the project very wrong.  I have a nontrivial desktop management application with "Mem Usage" of 1844kb, and a VM size of 316kb.  Check that you're actually optimizing the program, that you've stripped debug symbols, etc.  Also, carefully pick which functions you call: some DLLs cause other DLLs to be loaded, so you might be dragging along a lot of unneeded baggage.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

LordVader

Yeah, i'm still learning the diff compile options..
thx for the input probably is debug switches in compile options..

Kp

Quote from: LordVader on September 02, 2004, 06:27 PMYeah, i'm still learning the diff compile options.. thx for the input probably is debug switches in compile options..

What compiler(s) are you using?  The switches vary widely among the compilers.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

LordVader


LordVader

#5
These are my project settings under the C/C++ tab:
- General
Maximise speed:

/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"Release/Opbot.pch" /YX /Fo"Release/"


Minimize size:

/nologo /ML /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"Release/Opbot.pch" /YX /Fo"Release/"



- Code Generation
Processor: Blend*
Use Run Time Library: single-threaded*
Calling Convention: _cdecl*
Struct member alignment: 8 bytes*

- Optomizations:
Only_inline (for minimize size and maximize speed)

With it set to auto use precompiled headers..

Under the link tab has various lib's included, and checked values are:
Generate Debug info & Link incrementally.
With project options:

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/Opbot.pdb" /debug /machine:I386 /out:"Debug/Opbot.exe" /pdbtype:sept

Kp

Turn off incremental linking and rebuild.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

LordVader

Ahh Nice thx heh good bit smaller memory footprint and exe size now
41kb exe vs 61kb, and bout 500-800kb smaller in memory when first run.. good stuff

LordVader

#8
also using:

#ifdef NDEBUG
#pragma optimize("gsy",on)
#pragma comment(linker,"/RELEASE")
#ifdef _MERGE_RDATA_
#pragma comment(linker,"/merge:.rdata=.data")
#endif
#pragma comment(linker,"/merge:.text=.data")
#pragma comment(linker,"/merge:.reloc=.data")
#pragma comment(linker,"/ignore:4078")
#if _MSC_VER >= 1000
#pragma comment(linker,"/opt:nowin98")
#endif
#endif

From AggressiveOptomize.h reduces memory footprint even more :)

Just for reference, to other's using maximize speed decreases the memory footprint (of course), and minimize size can slightly reduce .exe size but at a cost of a higher memory footprint.

*Edit fixed typo.

Banana fanna fo fanna

I'm not an expert in this, but don't you want to use __fastcall?

Kp

Quote from: $t0rm on September 03, 2004, 09:26 AMI'm not an expert in this, but don't you want to use __fastcall?

Not necessarily.  Consider this example:
void _fastcall foo(int x, int y) {
  bar(1, 3);
  hmm(7, 9);
  p(x);
  q(y);
}


__fastcall requests the parameters come in in registers, but if your function already has uses for all the stable registers, it'll end up spending instructions kicking the operands out onto the stack for longer storage until they're used, thereby making the code longer.  My example doesn't quite follow this explanation, as I don't include anything to consume the other stable registers, but it illustrates the idea that if the parameter isn't used quickly, it might be better not to put it in a register.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Banana fanna fo fanna

The optimizer will automatically __fastcall anything that would be best called as __fastcall, right?

Kp

Quote from: $t0rm on September 04, 2004, 10:55 AMThe optimizer will automatically __fastcall anything that would be best called as __fastcall, right?

Not necessarily.  It can't do that if the caller and callee are in different files (especially since one might be available only as object code, and therefore a huge pain for the compiler to modify).  Whether it will automatically change them when it has the source to both depends heavily on the quality of your optimizer - I've never seen a decent Microsoft optimizer, so I can't say whether it would or not.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!