- Fri May 01, 2015 3:32 pm
#16223
Cal, thanks for pointing this out. Yes, I had missed it.
Sorry. But to be honest, I've looked through the code and it's as clear as mud. It's a good example of the FLOSS zero-commenting "because the code says it all" fails miserably. To get a better handle, I'd really need to to step through this with gdb. (if we have gdb remote for this system working).
If it does what I think you are implying then it broadly implements the sort of strategy that I've used myself and seen in other applications:
- Initially allocate X bytes on the stack, but it this overflows then realloc a working copy on the heap and realloc this as necessary.
- This way 95% of string buffer manipulation is cheap in terms of runtime cost but the code will handle longer strings.
- However, this isn't using standard malloc / free but is drawing down on a LIFO string stack.
Is this how you read it? If this summary is correct, then this initial allocation constant could easily be dropped to 128b, say. However this leads to a second issue:
LUAL_BUFFERSIZE is denormalised in that it is used for two quiet separate purposes: one is to defined this default stack allocated size of a
luaL_Buffer, and the second is in (
file.c and
liolib.c where it is used for allocating I/O buffers and defining I/O chunk sizes, which really need to be aligned to optimum flash write blocksizes.
None of thes other uses seem to constrain functionality, yet I cant' square this observation with the issues which seemed to be cured by an x4 on this size.
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