Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: How to interpret the difference in memory size between Teensy 4.1 and Due ?

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    19

    How to interpret the difference in memory size between Teensy 4.1 and Due ?

    I am in the process of transferring my project on my arduino due to the Teensy 4.1.
    One of the main reasons for this is the memory usage of my sketch.
    If I compare the memory usage of the sketch between the Due and the Teensy, the Teensy uses only 6% against 64% on the Due.
    That is the good news, however, the compiler indicates that global variables use 78% of the dynamic memory.
    Unfortunately, the compiler does not indicate this consumption for the Due, but I expected that I would have much more memory left with the Teensy. Or am I missing something ? And can extra psram mean anything ?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,195
    Hard to say what memory is being used and for what...

    I have a thread I did awhile ago, that talks some about the different regions of memory on the T4.x, that also shows some tools we hacked up to show additional information and the like:
    https://forum.pjrc.com/threads/57326...ferent-regions

    Also the T4.x there is additional information up on the main page for the T4: https://www.pjrc.com/store/teensy40.html
    (Note: on that page) PROGMEM Code - Functions defined with "PROGMEM"
    Should now read: PROGMEM Code - Functions defined with "FLASHMEM"

    There have also been a few threads on this recently including:
    https://forum.pjrc.com/threads/63435...AM-utilization

  3. #3
    Junior Member
    Join Date
    Sep 2020
    Posts
    19
    Thanks KurtE.
    It has now become a little clearer to me.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,447
    64% of flash memory used on Due means your program is taking about 328K. That's pretty large.

    On Teensy 4.1 many things compete for use of the first 512K of "tightly coupled" RAM. If all 328K of your program gets put into that RAM, it's going to leave only 184K for everything else. The good news is Due's RAM is only 96K, so odds are very good everything will fit even in the worst case of everything packing into the first 512K RAM. But you might not end up with much of that first 512K left over.

    The 2 easy things you can do to keep some of that 328K from consuming TCM RAM is use of FLASHMEM on functions which aren't speed critical, and PROGMEM on any arrays of constant data which isn't speed critical.

    You can also get access to the other 512K with malloc(). So if you have any large arrays or buffers, you might edit your code slightly to allocate those at startup with malloc() rather than having them as global or static variables.

    But TCM RAM (the first 512K) is the fastest memory. That's why so many things default to using it. If you want maximum performance, best to just go with the defaults. You can always do this stuff if you need more of the TCM space if your code & memory requirements grow.

  5. #5
    Junior Member
    Join Date
    Sep 2020
    Posts
    19
    thanks for your extra clarification Paul.
    it's clearer to me now and I'm going to try out some suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •