6

I'm developing S/W for some device which uses Linux O.S. So, the size of libraries (RAM/ROM) which I use is very important.

How can I easily calculate RAM / ROM required by my software? (including libraries I used). I think it's too easy question for experienced Linux developer.

Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
Wonil
  • 6,364
  • 2
  • 37
  • 55
  • 1
    This is in fact a difficult question. If your program uses dynamic memory allocation `malloc` or has nontrivial call patterns (especially if it has recursion), it's impossible even theoretically to predict how much RAM will be needed for the heap/stack. There are analyzers that work reasonably well at determining the stack requirements for typical embedded programs, but they often don't come cheap. – Gilles 'SO- stop being evil' Oct 24 '11 at 21:54

1 Answers1

4

Run

size <object>

or

size <archive>

or

size <shared-object>

. (or "target-"size in case you're cross-compiling: arm-size if you're using arm-gcc)

It will give you a

text    data     bss     dec     hex filename

table where text is program-size, bss the initialized globals and data the read-only data.

While this answers your question, you probably will want to use a specific LdScript (when using ld as linker) where you will place the sections into the available memories manually when doing the final link.

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • 2
    Note that this tool only displays the static memory. Run-time memory use will be larger. How much larger depends on the program and it's use of the stack and heap. – Kevin Vermeer Oct 25 '11 at 13:24
  • Also can use "ldd" to check shared libraries. With "ldd" and "size", I can guess how much ROM/RAM used including libraries. – Wonil Oct 31 '11 at 07:21