diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-01-25 23:49:09 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-01-25 23:49:09 +0000 |
commit | d35c21587a4139031c077fd122252217a4713681 (patch) | |
tree | 7bd14fd247492c00f3d38ae1dbd7727e03fda9ad /docs/style-guide.txt | |
parent | ffde8673fe8b2c32076aa3e01eab1fefc5f08e86 (diff) | |
download | busybox-w32-d35c21587a4139031c077fd122252217a4713681.tar.gz busybox-w32-d35c21587a4139031c077fd122252217a4713681.tar.bz2 busybox-w32-d35c21587a4139031c077fd122252217a4713681.zip |
Commit Larry Doolittle's buffers-on-stack/buffers-via-malloc patch.
-Erik
Diffstat (limited to 'docs/style-guide.txt')
-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 | |||
402 | memory penalty for this buffer, even if the applet that uses said buffer is | 402 | memory penalty for this buffer, even if the applet that uses said buffer is |
403 | not run. This can be fixed, thusly: | 403 | not run. This can be fixed, thusly: |
404 | 404 | ||
405 | static char *buffer | 405 | static char *buffer; |
406 | ... | 406 | ... |
407 | other_func() | 407 | other_func() |
408 | { | 408 | { |
@@ -418,7 +418,7 @@ mallocing the buffers (and thus growing the text size), buffers can be | |||
418 | declared on the stack in the *_main() function and made available globally by | 418 | declared on the stack in the *_main() function and made available globally by |
419 | assigning them to a global pointer thusly: | 419 | assigning them to a global pointer thusly: |
420 | 420 | ||
421 | static char *pbuffer | 421 | static char *pbuffer; |
422 | ... | 422 | ... |
423 | other_func() | 423 | other_func() |
424 | { | 424 | { |
@@ -430,13 +430,13 @@ assigning them to a global pointer thusly: | |||
430 | pbuffer = buffer; /* but available globally */ | 430 | pbuffer = buffer; /* but available globally */ |
431 | ... | 431 | ... |
432 | 432 | ||
433 | Thus: | 433 | This last approach has some advantages (low code size, space not used until |
434 | - global static buffers are eliminated | 434 | it's needed), but can be a problem in some low resource machines that have |
435 | - we don't grow the text segment as much because no malloc() call is made; | 435 | very limited stack space (e.g., uCLinux). busybox.h declares a macro that |
436 | memory is automatically allocated on the stack when execution context | 436 | implements compile-time selection between xmalloc() and stack creation, so |
437 | enters the function. (We still grow text a little bit because of the | 437 | you can code the line in question as |
438 | assignment, but that's cheap compared to a function call.) | 438 | RESERVE_BB_BUFFER(buffer, BUFSIZ); |
439 | - the buffer is still available globally via the pointer | 439 | and the right thing will happen, based on the customer's configuration. |
440 | 440 | ||
441 | 441 | ||
442 | 442 | ||