-->
Page 1 of 1

Memory management. Should HTML be on the heap or stack?

PostPosted: Mon Aug 08, 2016 8:31 pm
by paulfer
Hi All,

OK, so coming from the privileged, albeit spoilt world of c# and GC I have a memory question for you.

I am developing a AP to serve up approx. 2.6 KB of HTML. I store the HTML in a txt file using SPIFFS.

My question is Three-fold:

1. Does the heap/stack allocation work the same as standard c?
2. With regards to memory utilisation, would I be better off to malloc a char[] aray and read the bytes from the .txt file into it and store this 2.6 KB on the heap (and then free() it), or should I just declare the char[] in a function and store it on the stack?
3. Does a char[x] array also get popped off the stack in the same way as int's and long's?

I thank you all in advance,

Paul

Re: Memory management. Should HTML be on the heap or stack?

PostPosted: Thu Aug 11, 2016 10:00 am
by mrburnette
@Paul,

From: http://domoticx.com/sdk-esp8266-xtensa-architecture-toolchain/
Xtensa lx106 architecture toolchain (100% OpenSource), based on following projects:
https://github.com/jcmvbkbc/crosstool-NG
https://github.com/jcmvbkbc/gcc-xtensa
https://github.com/jcmvbkbc/newlib-xtensa
https://github.com/tommie/lx106-hal
The source code above originates from work done directly by Tensilica Inc., Cadence Design Systems, Inc, and/or their contractors.


So, essentially the ESP8266 tools are GCC and RedHat's Newlib. The memory map for an embedded device supported by GCC typically looks like:
http://www.geeksforgeeks.org/memory-layout-of-c-program/

Your questions are best answered by studying on the GCC docs, IMO.
This may also help:
http://stackoverflow.com/questions/14290879/disassembling-a-flat-binary-file-using-objdump

Ray