Would it be possible to somehow reduce stack requirements?
Opened this issue · 1 comments
Compiling the code with -fstack-usage
shows that some of the functions use a lot of stack - for example ufat_dir_find_path()
is the most stack-hungry one, using 848 B (note - values for x86_64, but for an embedded MCU they are more-or-less similar) and ufat_dir_read()
requests 672 B. But here's the problem - ufat_dir_find_path()
calls ufat_dir_read()
, so any call to ufat_dir_find_path()
requires almost 1.5 kB of stack.
I noticed that the majority of this usage comes from ufat_dir_find_path()
having a char name[UFAT_LFN_MAX_UTF8];
buffer (768 B) and then ufat_dir_read()
having struct ufat_lfn_parser lfn;
which internally has uint16_t buf[UFAT_LFN_MAX_CHARS];
(510 B).
This made me wonder, whether there's an option to somehow reduce this amount? I don't know much about FAT internals and LFN, so I'm asking what options are possible and what things have to stay that way and cannot be changed.
- Maybe a configuration option (
#define
) would be possible, which would disable USC2 / UTF-8 conversions, leaving only ASCII values valid - this would maybe allowUFAT_LFN_MAX_UTF8
to be 255 instead of 3 * 255? Or maybe I could just redefineUFAT_LFN_MAX_UTF8
to 255 and this would give the same (or similar) effect? - Would it be possible to parse LFN "in-place"? Basically - would it be possible to parse USC2 to UTF-8 in
ufat_ucs2_to_utf8()
in-place (possibly in reverse or in two passes?) instead of from one buffer to another? - Any other ideas? (;
I'm asking this because uFAT code in my project (wrapped in some layers) does NOT work with 4 kB of stacks, which I personally consider "a lot", so I wondering whether this can be somehow reduced.