10. Programming Zhu Ji Nanxiong note 10 save space
This famous saying:"positive people see an opportunity in every crisis, while negative people see some kind of hardship at every opportunity." "
Welcome reprint, Reprint please indicate source: http://blog.csdn.net/notbaron/article/details/48420257
The previous algorithms are all about accelerating the program, and this chapter is mainly about how to save the program space.
Simplicity can derive functionality, robustness, and speed and space. The earliest UNIX was developed on a machine running on 8,192 18-bit words. They mentioned in the paper that:
"In terms of the system and its software, there is always a fairly serious spatial constraint. If the demand for reasonable efficiency and strong ability is at the same time, the spatial constraints not only have economic significance, but also make the design more elegant. "
By making the problem simple, complex problems can be simplified. Save a lot of storage space at the same time.
The authors cite an example to save the storage space Toad feels very ingenious.
About this matrix as shown in Figure 1
Can be stored by 200x200=40000 elements. Assuming that each element is 32 bits, that's almost 160KB of space.
Using 3 arrays is a clever idea. Figure 2
The points in column I are represented by the elements in the array row and pointnum that are between firstincol[i] and firstincol[i+1]-1.
Firstincol has only 200 elements, and the number of row and pointnum arrays is consistent with the number of actual numbers that are in total. The sparse data structure features are fully utilized here.
In addition, the elements in the row array are less than 200 and can actually be implemented using a single byte.
Finally, the author gives the space technology about data and program. 1. About Data space technology
L do not store, recalculate. Use calculations to exchange space.
L Sparse data structure.
L Information compression. The object is encoded in a compressed manner to reduce storage space.
L allocation policy. Sometimes the way space is used is more important than the amount of use.
L garbage Collection. Recycling of discarded storage space. 2. About Code Space Technology
l function definition. By replacing common patterns in code with functions, you can simplify your programs and reduce space requirements. Microsoft has removed the rarely used functions to compress the entire Windows system into a more compact Windows CE.
L explain the procedure. Use an interpreter to replace a long line of program text.
L translate into machine language. This cost-effective is relatively low, generally used in memory of valuable systems, such as DSP.