RAM usage with arm-gcc

From: Francis Cagney (fpcagney_at_yahoo.com)
Date: 03/31/04


Date: 31 Mar 2004 02:44:42 -0800

I'm trying to squeeze the amount of RAM my software will occupy, and
char pointers are taking up a very strange amount of space. I'm using
the gcc compiler for arm.

The offending software is below, and the const CHAR etc declarations
take up 260 bytes. The mapfile reports that each declaration below
takes up 4 bytes which stands to reason, TX_LANGUAGES is an enum, and
the rest are pointers.

But then we would expect this module to use 9x4 = 36.

Instead it uses 8x32 + 4 = 260 according to the mapfile. BTW I'm
assuming the COMMON describes the amount of global data the modules
uses. I can see that .data defines only the static data for that
module, and global variables are not described by the .data part of
the mapfile.

TXCountryIndex 0x4 txmain.o
TXOther 0x4 txmain.o
TXWeekDays 0x4 txmain.o
TXSelectedLanguage 0x4 txmain.o
TXLanguages 0x4 txmain.o
TXGenie 0x4 txmain.o
TXMenu 0x4 txmain.o
TXCountryName 0x4 txmain.o
TXSoftKey 0x4 txmain.o
LOAD txmain.o
 .text 0x0000fea8 0x250 txmain.o
                0x000276c0 0x1b txmain.o
 COMMON 0x00029d40 0x104 txmain.o
 .comment 0x00000240 0x12 txmain.o

If I move one of the declarations to another file in the project, this
module will reduce by 32 bytes of RAM, and the other module increase
by 4. Everytime I move of these declarations to another module this
module reduces by 32, and the other increasas by 4.

However if I move 2 declarations to another module this module will
now reduce by 64, and the other increase by 36.

So I seem to save 28 bytes by scattering those delcaration in unquite
modules.

TX_LANGUAGES TXSelectedLanguage;

typedef char CHAR

const CHAR *TXCountryIndex;
const CHAR * const *TXMenu;
const CHAR * const *TXOther;
const CHAR * const *TXCountryName;
const CHAR * const *TXWeekDays;
const CHAR * const *TXSoftKey;
const CHAR * const *TXLanguages;
const CHAR * const * const *TXGenie;
 

void TXLanguageSelect( TX_LANGUAGES Lang )
  {
  TXSelectedLanguage = Lang;
  switch (Lang)
    {
    case TXLanguageEnglish:
      TXMenu = TXMenuEnglish;
      TXOther = TXOtherEnglish;
      TXCountryName = TXCountryNameEnglish;
      TXCountryIndex = TXCountryIndexEnglish;
      TXWeekDays = TXWeekDaysEnglish;
      TXSoftKey = TXSoftKeyEnglish;
      TXLanguages = TXLanguagesEnglish;
      TXGenie = TXGenieEnglish;
      break;

    case TXLanguageFrench:
      TXMenu = TXMenuFrench;
etc



Relevant Pages