diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-01-26 02:49:09 +0300 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-01-26 02:49:09 +0300 |
commit | d35c21587a4139031c077fd122252217a4713681 (patch) | |
tree | 7bd14fd247492c00f3d38ae1dbd7727e03fda9ad /docs | |
parent | ffde8673fe8b2c32076aa3e01eab1fefc5f08e86 (diff) |
Commit Larry Doolittle's buffers-on-stack/buffers-via-malloc patch.
-Erik
Diffstat (limited to 'docs')
-rw-r--r-- | docs/style-guide.txt | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/style-guide.txt b/docs/style-guide.txt index 9a3b10207..1a04e4474 100644 --- a/docs/style-guide.txt +++ b/docs/style-guide.txt @@ -402,7 +402,7 @@ The problem with these is that any time any busybox app is run, you pay a memory penalty for this buffer, even if the applet that uses said buffer is not run. This can be fixed, thusly: - static char *buffer + static char *buffer; ... other_func() { @@ -418,7 +418,7 @@ mallocing the buffers (and thus growing the text size), buffers can be declared on the stack in the *_main() function and made available globally by assigning them to a global pointer thusly: - static char *pbuffer + static char *pbuffer; ... other_func() { @@ -430,13 +430,13 @@ assigning them to a global pointer thusly: pbuffer = buffer; /* but available globally */ ... -Thus: - - global static buffers are eliminated - - we don't grow the text segment as much because no malloc() call is made; - memory is automatically allocated on the stack when execution context - enters the function. (We still grow text a little bit because of the - assignment, but that's cheap compared to a function call.) - - the buffer is still available globally via the pointer +This last approach has some advantages (low code size, space not used until +it's needed), but can be a problem in some low resource machines that have +very limited stack space (e.g., uCLinux). busybox.h declares a macro that +implements compile-time selection between xmalloc() and stack creation, so +you can code the line in question as + RESERVE_BB_BUFFER(buffer, BUFSIZ); +and the right thing will happen, based on the customer's configuration. |