Data Space Technology
---- How to reduce the storage space required by the program
1. Do not store and re-calculate.If we need to re-compute a given object without saving it at any time, we can reduce the space required for this object. This method is used to change computing time to space. Only objects that need to be stored can be re-computed according to their descriptions.
2. sparse data structure
Example 1:Storage of sparse matrices (multiple 0 or other identical items ).
Example 2:Using pointers to share large objects eliminates the overhead required to store multiple copies of the same object (passing array parameters ), when modifying a shared object, the programmer must exercise caution that all owners of the object want to modify it.
Example 3:It stores calendars between and, and does not need to store calendars of different years. Instead, you only need to provide 14 standard calendars (for any year, there are only seven possibilities for the week of March, and there are only two possibilities for a leap year or a non-leap year) and a table that provides the calendar number for every year from 1970-2070.
3. Data CompressionThe object is encoded by compression to reduce storage space.
Example 1:Use standard Compression Algorithms
Example 2:Based on the specific application environment, such as the processing of decimal numbers, two decimal numbers can be compressed to one byte storage. Encoding: c = A * 10 + B; decoding: A = C/10; B = C % 10;
4. Allocation PolicyDynamic On-Demand allocation: requests data space as required, instead of pre-allocation.
5. Garbage CollectionRecycle and reuse obsolete buckets so that unused buckets can be reused.
Example 1:Reuse unused bits of some fields. For example, the Linux base tree uses the integer address value (which can be divisible by 4) as the lower two.
Data Space Technology
---- How to reduce the storage space occupied by program code
1. Function Definition
By using functions to replace common patterns in code, you can reduce space requirements and increase clarity.
Microsoft deleted a rarely used function and compressed its entire windows into a more compact Windows CE, allowing it to run on a smaller memory "Mobile Computing Platform.
2. InterpreterIn graphics programs, a long line of program text is replaced by a 4-byte interpreter. Use the interpreter programmed with "formatted letters.
3. Translate to machine languageConverts a source language to a machine language. Compile the key parts for implementation.