[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Memory Size Report

From: Ned Konz
Subject: Re: [avr-gcc-list] Memory Size Report
Date: Sun, 5 Feb 2006 13:18:26 -0800

On Feb 5, 2006, at 12:44 PM, Peter Harrison wrote:

I am using the current WinAVR 20060125

A program compiled with this shows a memory usage report in the compiler output stream. It looks like this:

AVR Memory Usage
Device: atmega32

Program:   24392 bytes (74.4% Full)
(.text + .data + .bootloader)

Data:       2733 bytes (133.4% Full)
(.data + .bss + .noinit)

My first question is why the .data segment shows as being counted twice. Does this represent the code space needed to store the initial values as well as the RAM space they will take up?

Yes. But only for explicitly initialized globals/statics.

When I look at the map file I see these lines for the .data section:

.data           0x00800060      0x4ec load address 0x00005a5c
                0x00800060                PROVIDE (__data_start, .)
 .data          0x00800060      0x141 gnumaximus.o
                0x00800060                menusize
 .data          0x008001a1        0xb maze.o
 .data          0x008001ac        0x2 motors.o
                0x008001ac                wallTrackRight
                0x008001ad                wallTrackLeft
 .data          0x008001ae      0x39e setup.o
                0x0080054c                . = ALIGN (0x2)
                0x0080054c                _edata = .
                0x0080054c                PROVIDE (__data_end, .)

If I take out some lines with static strings (like sprintf("blah") lines), both the amount of RAM used and the size of the .data section decrease. These strings only need exist in flash memory so what can I do? Why do they seem to be counted twice and where are they really stored?

Look at the avr-libc manual; there are provisions for both defining static constants in flash, as well as versions of the stdlib and stdio functions that deal with strings that will work with strings in flash. Look at the documentation for <avr/pgmspace.h>

For instance,

#include <avr/io.h>
#include <avr/pgmspace.h>

const char s1[] = "abc";  /* will take up both RAM and flash */

const char PROGMEM s2[] = "def" /* will take only flash, but you have to use different functions to access it */


char myBuffer[30];      /* in RAM */
sprintf(myBuffer, s1);
/* but */
sprintf_P(myBuffer, s2);

Ned Konz

reply via email to

[Prev in Thread] Current Thread [Next in Thread]