Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to increase heap size by reducing dynamic memory size? #3031

Closed
ericmnel opened this issue Mar 9, 2017 · 2 comments
Closed

How to increase heap size by reducing dynamic memory size? #3031

ericmnel opened this issue Mar 9, 2017 · 2 comments

Comments

@ericmnel
Copy link

ericmnel commented Mar 9, 2017

Basic Info

Hardware

Hardware: Wroom-02
Core Version: 2.3.0

Description

I'm running out of heap, and would like to move 5k of memory from "dynamic memory" to heap maybe by changing the memory boundaries or something, i.e. the dynamic memory referred to by the compile message:

"Sketch uses 374,909 bytes (35%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 48,364 bytes (59%) of dynamic memory, leaving 33,556 bytes for local variables. Maximum is 81,920 bytes."

Is there any way to do this?

Settings in IDE

Module: Wroom-02
Flash Size: 4MB/1MB
CPU Frequency: 80Mhz
Flash Mode: dio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ck

@bebo-dot-dev
Copy link

bebo-dot-dev commented Mar 9, 2017

I think you're thinking about it wrong, probably because that sketch usage output message that gets squirted out from the arduino IDE compiler doesn't really clarify what the numbers mean or what dynamic memory is.

81,920 bytes refers to the total amount of available user RAM on the device. This is "dynamic memory". This RAM gets sliced up and allocated between .data, .rodata and .bss depending on how your code is structured and whatever is left over after allocation to those parts is the available runtime stack and heap memory where stack grows/shrinks at one end of this free RAM and heap grows/shrinks at the other end. If things get so bad where stack and heap meet/overlap due to RAM depletion, you get an exception and a reboot.

Hopefully this should make it clear that the only possible way to "move 5k of memory from "dynamic memory" to heap" is by way of optimizing your code so that less of .data, .rodata and .bss is used, thus making more RAM available for the stack and heap.

Here's a decent article that goes into further detail about .data, .rodata, .bss and also .irom0.text: http://tech.scargill.net/esp8266-ram/

Only you can see your code at the moment though so you're on your own about how you might go about optimizing your code..

@ericmnel
Copy link
Author

ericmnel commented Mar 9, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants