go away spammer

Author Topic: How much memory are we using?  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

Offline TomasTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
How much memory are we using?
« on: May 27, 2009, 01:38:36 AM »


26kByte of a total 64? Or 6.8kByte of 64kByte?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How much memory are we using?
« Reply #1 on: May 30, 2009, 09:43:36 AM »
26kByte of a total 64

You should use the latest Axon software, you'll see this instead:


Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: How much memory are we using?
« Reply #2 on: May 30, 2009, 10:53:24 AM »


26kByte of a total 64? Or 6.8kByte of 64kByte?

The 'text' figure is how much program code you have got
The 'data' figure is the amount of data that you have set to have an initial value eg stuff like:  char buffer[] = { 1,2,3,4,5 }; or int speed=10;
The 'bss' figure is the amount of data that has not been initialised - eg stuff like:   char  buffer[1024];

As you can see from the figures in Admins screen shot then the amount of memory taken up on the chip is 'text' + 'data' as it obviously needs to store your code but it also needs to store the values of the initialised variables so that on power up it can copy these initial values out into the RAM area. Thats why its got practice to NOT initialise a variable unless you need to - since it will take up program space.
Also the amount of RAM required at runtime is 'data + bss' - ie the sum of your initialised and unintialised data.

The 'hex' figure of '6800' is just the hexadecimal (base 16) value of the 'dec'imal (base 10) number 26624. 

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: How much memory are we using?
« Reply #3 on: May 30, 2009, 11:13:48 AM »
Also the amount of RAM required at runtime is 'data + bss' - ie the sum of your initialised and unintialised data.

Don't forget the stack! and the heap if you use malloc.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: How much memory are we using?
« Reply #4 on: May 30, 2009, 11:45:11 AM »
Don't forget the stack! and the heap if you use malloc.

Thats an excellent point. Especially the use of malloc. I discovered a problem when using structures in my library. So I'll bore you C gurus with what I found with a nonsense example .....

Code: [Select]
// Declare a structure to hold the data about a thing.

typedef struct s_thing {
int width;
int height;
char description[256];
} THING;
// Now declare some things.....
THING thing1 = { 1,20, "A tall and thin thing"};
THING thing1 = { 20,1, "A thin and very short thing"};

The problem here is that 'thing1' and 'thing2' are initialised with values. The 'THING' structure requires about 260 bytes for each of them. Since the data is initialised then it goes into the 'data' segment and therefore takes up 520 bytes of your program memory !!!

Obviously this is a silly example. But if the structure was for a UART then the character array may only be used as a comms buffer at run time so you dont need the character array to be initialised but you still need the other variables to be initialised. In which case change the structure to be:

Code: [Select]
// Declare a structure to hold the data about a thing.

typedef struct s_thing {
int width;
int height;
char* description;
} THING;
// Now declare some things.....
THING thing1 = { 1,20, 0};
THING thing1 = { 20,1, 0};

And then have a method to initialise each 'THING' which uses malloc to allocate the space for the description. This saves 512 bytes of program memory!  But since you are using 'malloc' then the compiler will not show you that an extra 512 bytes of memory required as it has no way of knowing. So there is a big benefit but also a big 'gotcha' if you forget that you've done the mallocs.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here