- Wed Nov 18, 2015 7:22 pm
#34467
It's pretty dumb in its estimate as it simply uses the SDK API call
system_get_free_heap_size(), and AFAIK this simply does a count up / down on malloc and free requests. However: (i) heap can get badly fragmented and (ii) any compilation hammers the heap and fragments it badly. To an extent you can mitigate this by doing
luac.cross on your host to compile code on the host or using
node.compile() on the target to save the code to lc files and run this.
If you need to keep debug line info (on the latest dev builds), then do your build with
#define LUA_OPTIMIZE_DEBUG 2 (see
Lua Compact Debug (LCD), and do the
string.dump(loadfile(file)) trick to write out lc files which contain compressed line info. Do this as a separate "Compile my code" step and then restart before running the app. This gives you the double win of saving about 40% of your heap used to store the Lua code and avoiding the compile hit.
You could also use some of the overlay techniques that I discuss in my FAQ.
Please see my
Developer FAQ for Q&A on nodeMCU Lua before asking a question here that's already been answered. This and the other official documentation should be your first reference for developing Lua Apps