standards: Memory Usage
1
1 4.11 Memory Usage
1 =================
1
1 If a program typically uses just a few meg of memory, don't bother
1 making any effort to reduce memory usage. For example, if it is
1 impractical for other reasons to operate on files more than a few meg
1 long, it is reasonable to read entire input files into memory to operate
1 on them.
1
1 However, for programs such as 'cat' or 'tail', that can usefully
1 operate on very large files, it is important to avoid using a technique
1 that would artificially limit the size of files it can handle. If a
1 program works by lines and could be applied to arbitrary user-supplied
1 input files, it should keep only a line in memory, because this is not
1 very hard and users will want to be able to operate on input files that
1 are bigger than will fit in memory all at once.
1
1 If your program creates complicated data structures, just make them
1 in memory and give a fatal error if 'malloc' returns 'NULL'.
1
1 Memory analysis tools such as 'valgrind' can be useful, but don't
1 complicate a program merely to avoid their false alarms. For example,
1 if memory is used until just before a process exits, don't free it
1 simply to silence such a tool.
1