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

Would it be possible to somehow reduce stack requirements? #14

Open
FreddieChopin opened this issue Sep 13, 2019 · 1 comment
Open

Would it be possible to somehow reduce stack requirements? #14

FreddieChopin opened this issue Sep 13, 2019 · 1 comment

Comments

@FreddieChopin
Copy link
Contributor

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 allow UFAT_LFN_MAX_UTF8 to be 255 instead of 3 * 255? Or maybe I could just redefine UFAT_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.

@dlbeer
Copy link
Owner

dlbeer commented Sep 14, 2019 via email

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