Teensy 4.1 Dynamic Memory Usage

Status
Not open for further replies.

bvernham

Well-known member
Is there a way to find out where the RAM is going.

I have a bunch of defines set up for diagnosing stuff.

Instead of doing a giant debug I am going piece by peace.

So each debug is just a few "cout" but I am not defining any new ram variables.

So right now I am at 25% usage with no debug defines.

I I turn a one on that is just a few cout I just to 32%.

I am trying to understand where the "7%" is going to output a few comments to the serial monitor?

As part of the normal initialization I am already using cout to just show a few statements about the initialization progress so the Serial is already active an as I am using the SDFat I am already using
static ArduinoOutStream cout(Serial);

Just interested in figuring out where the "7%" is going.

Thanks

Bruce
 
Not sure if it requires 'verbose' on compile - but the Teensy build - at least with the latest TeensyDuino 1.54 Beta 9 release exposes some details of memory allocation:
Code:
Memory Usage on Teensy 4.1:
FLASH: code:26760, data:3864, headers:7256   free for files:8088584
RAM1: variables:12992, code:24136, padding:8632   free for local variables:478528
RAM2: variables:12384  free for malloc/new:511904

That doesn't show percentages - but 7% of 512KB seems to be about 32KB.

RAM1 above is the FAST 512KB of RAM where by default all USER code and data reside. Unless marked to stay in FLASH.

It seems that the added 'cout' code it exhausting a 32KB block in RAM1 where code is stored and allocating another 32KB block to hold the code and strings.

See here for more details on the memory : pjrc.com/store/teensy41.html#memory
 
I am using Arduino 1.8.13 and the latest Teensy duino.

Cout is not the issue at I replaced a println with cout in the setup and had no impact on the memory usage:

Opening Teensy Loader...
Sketch uses 110832 bytes (1%) of program storage space. Maximum is 8126464 bytes.
Global variables use 135860 bytes (25%) of dynamic memory, leaving 388428 bytes for local variables. Maximum is 524288 bytes.

Anyways just looking for some ideas.

Thanks

Bruce
 
issue is not println or cout - it is added code and perhaps enclosed strings taking program memory.

See line #1 of p#2 and in IDE ( Ctrl+, ) enable :: ...'verbose' output on compile
> output should appear formatted as shown in p#2 that shows the allocation of RAM1 as split between CODE and Variables/DATA

Some of the startup code PJRC uses is marked to stay in FLASH See "#memory" link in p#2, any other added code or constant strings in code { unless strings are marked with f() as shown in that link } go into the ITCM area of RAM1 - it is allocated in 32KB blocks.

So one 32KB block being filled allocates into the next 32KB block ... 7% of code space as noted p#2.
 
Status
Not open for further replies.
Back
Top