From d35c21587a4139031c077fd122252217a4713681 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 25 Jan 2001 23:49:09 +0000 Subject: Commit Larry Doolittle's buffers-on-stack/buffers-via-malloc patch. -Erik --- docs/style-guide.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'docs/style-guide.txt') 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. -- cgit v1.2.3