Re: Minimizing executable memory usage

"Byron Guernsey" <byron-s/[email protected]> Thu, 18 Aug 2005 13:07:24 -0400
Newsgroups gmane.comp.windows.ce.freeware
Message-ID <000601c5a417$4df0b1b0$0a00a8c0@antigravity>
> What processor do you compile for? You might try THUMB/Interworking  for 
> ARM
> processors.

I'm only targetting ARM devices at the moment.  Being fairly new to PocketPC 
development I had not heard of THUMB/ARM Interworking.  I just googled it 
and it sounds like the Thumb instruction set is a 16 bit instruction set, 
which could reduce code size significantly.  Is there a THUMB FAQ?

> How large is the executable?

The executable itself, when compiled for Release, is 193,536 bytes.  It uses 
the GDAPIDraw library, which is a DLL of about 350,000 bytes, and the Hekkus 
Sound DLL 140,000 bytes.

> How do you measure memory usage?

Thats a good question... I've not found an easy way to estimate.  I've been 
using the Windows build to estimate the memory usage, which may not be very 
accurate, but its allowed me to watch the growth of the project over time 
from a 4 meg footprint on the PC to a 8 meg footprint on the PC.   If there 
is a better method to get this data from the PocketPC I would love to hear 
it.  The remote PPC tools (process viewer, heap walker, etc) are not much 
help.  I thought about looking at the Memory control panel application 
before and after launching the process, but I've got the process locked to 
full screen until it exits and I have not yet added an escape method.

> Do you use lot's of inline-functions?

Yes.  I've inlined small functions a lot to help performance in rendering 
loops.

> Do you use special libraries?

GDAPIDraw and Hekkus Sound lib.  I use STL Port 5.6.x for its containers.

> Do you have large static arrays?

Not many - I tend to use STL an allocate dynamically when possible.  But 
this does give me an idea of some things to look at- I did initialize a 
static string array with packet names for debugging and I'm sure this is 
being compiled into the release version.  Its got to be pretty large with 
Unicode text. I can remove this from the release build.

Are you aware of any good static code analysis tools for analyzing relative 
class size?

> Send output of "dumpbin /headers <your exe>"

Output Follows:

Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file PocketDrakkar.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
             1C0 machine (ARM)
               5 number of sections
        4304B673 time date stamp Thu Aug 18 12:25:23 2005
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
             10F characteristics
                   Relocations stripped
                   Executable
                   Line numbers stripped
                   Symbols stripped
                   32 bit word machine

OPTIONAL HEADER VALUES
             10B magic #
            6.24 linker version
           23200 size of code
            C400 size of initialized data
               0 size of uninitialized data
           22B04 RVA of entry point
            1000 base of code
           25000 base of data
           10000 image base
            1000 section alignment
             200 file alignment
            4.00 operating system version
            0.00 image version
            4.20 subsystem version
               0 Win32 version
           32000 size of image
             400 size of headers
               0 checksum
               9 subsystem (Windows CE GUI)
               0 DLL characteristics
           10000 size of stack reserve
            1000 size of stack commit
          100000 size of heap reserve
            1000 size of heap commit
               0 loader flags
              10 number of directories
               0 [       0] RVA [size] of Export Directory
           26068 [      78] RVA [size] of Import Directory
           2C000 [    545C] RVA [size] of Resource Directory
           2A000 [    1C08] RVA [size] of Exception Directory
               0 [       0] RVA [size] of Certificates Directory
               0 [       0] RVA [size] of Base Relocation Directory
               0 [       0] RVA [size] of Debug Directory
               0 [       0] RVA [size] of Architecture Directory
               0 [       0] RVA [size] of Special Directory
               0 [       0] RVA [size] of Thread Storage Directory
               0 [       0] RVA [size] of Load Configuration Directory
               0 [       0] RVA [size] of Bound Import Directory
           27000 [     328] RVA [size] of Import Address Table Directory
               0 [       0] RVA [size] of Delay Import Directory
               0 [       0] RVA [size] of Reserved Directory
               0 [       0] RVA [size] of Reserved Directory


SECTION HEADER #1
   .text name
   2316C virtual size
    1000 virtual address
   23200 size of raw data
     400 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
60000020 flags
         Code
         Execute Read

SECTION HEADER #2
  .rdata name
    1FA0 virtual size
   25000 virtual address
    2000 size of raw data
   23600 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         Read Only

SECTION HEADER #3
   .data name
    2E58 virtual size
   27000 virtual address
    2A00 size of raw data
   25600 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
C0000040 flags
         Initialized Data
         Read Write

SECTION HEADER #4
  .pdata name
    1C08 virtual size
   2A000 virtual address
    1E00 size of raw data
   28000 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         Read Only

SECTION HEADER #5
   .rsrc name
    545C virtual size
   2C000 virtual address
    5600 size of raw data
   29E00 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
40000040 flags
         Initialized Data
         Read Only

  Summary

        3000 .data
        2000 .pdata
        2000 .rdata
        6000 .rsrc
       24000 .text

Thanks for your advice.  Its already helped me identify a few areas where I 
might be able to trim the size.  I've also started to refactor some classes 
to reduce duplicate code, but so far its been minimal gains by moving 
methods up into parent classes.

Byron



------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12hr3bao0/M=362329.6886308.7839368.1510227/D=groups/S=1707281942:TM/Y=YAHOO/EXP=1124392047/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992
">Fair play? Video games influencing politics. Click and talk back!</a>.</font>
--------------------------------------------------------------------~->