《深入理解计算机系统》的原文摘录

  • 要知道不同的操作系统或机器,sizeof的结果是不同的,所以,为了提高程序代码的可移植性,尽量使用sizeof (查看原文)
    black 2014-10-20 20:24:18
    —— 引自第26页
  • int val = 0x12345678; byte_pointer valp = (byte_pointer) &val; show_bytes(valp, 1); /* A. */ show_bytes(valp, 2); /* B. */ show_bytes(valp, 3); /* C. */ (查看原文)
    black 2014-10-21 00:12:00
    —— 引自第30页
  • 如果我们有一个32位的地址空间、4KB的页面和一个4字节PTE,那么即使应用程序所引用的只是虚拟地址空间中很小的一部分,也总是需要一个4MB的页表驻留在存储器中。 (查看原文)
    black 2014-10-22 19:41:54
    —— 引自第546页
  • 每个超单元存储主存的一个字节,而用相应超单元地址为(i,j)的8个超单元来表示主存中字节地址A处的64位双字。 (查看原文)
    black 2014-10-25 14:44:16
    —— 引自第385页
  • 1.重复引用同一个变量的程序具有良好的时间局部性 2.对于具有步长为k的引用模式的程序,步长k越小,空间局部性越好。具有步长为1的引用模式的程序有很好的空间局部性。在存储器中以大步长跳来跳去的程序空间局部性会很差 3.对于取指令来说,循环有好的时间和空间局部性。循环体越小,循环迭代次数越多,局部性越好 (查看原文)
    black 2014-10-25 19:39:30
    —— 引自第403页
  • You are poised for an exciting journey. If you dedicate yourself to learning the concepts in this book, then you will be on your way to becoming a rare "power programmer," enlightened by an understanding of the underlying computer system and its impact on your application programs. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • We begin our study of systems by tracing the lifetime of the hello program, from the time it is created by a programmer, until it runs on a system, prints its message, and terminates. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • The source program is a sequence of bits, each with a value of 0 or 1, organized in 8-bit chunks called. Each byte represents some text character in the program. Most modern systems represent text characters using the ASCII standard that represents each character with a unique byte-sized integer value. For example, Figure 1.2 shows the ASCII representation of the hello.c program. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • The hello.c program is stored in a file as a sequence of bytes. Each byte has an integer value that corresponds to some character. The representation of hello.c illustrates a fundamental idea: All information in a system-including disk files, programs stored in memory, user data stored in memory, and data transferred across a network-is represented as a bunch of bits. The only thing that distinguishes different data objects is the context in which we view them. For example, in different context, the same sequence of bytes might represent an integer, floating-point number, character string, or machine instruction. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • In order to run hello.c on the system, the individual C statements must be translated by other programs into a sequence of low-level machine-language instructions. These instructions are then packaged in a form called an executable object program and stored as a binary disk file. Object programs are also referred to as executable object files. On a Unix system, the translation from source file to object file is performed by a compiler driver: unix> gcc - o hello hello.c (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • The preprocessor (cpp) modifies the original C program according to directives that begins with the # character. For example, the #include <stdio.h> command in line 1 of hello.c tells the preprocessor to read the contents of the system header file stdio.h and insert it directly into the program text. The result in another C program, typically with the .i suffix. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • The compiler (ccl) translates the text file hello.i into the text file hello.s, which contains an assembly-language program. Each statement in an assembly-language program exactly describes one low-level machine-language instruction in a standard text form. (查看原文)
    Oasis 2014-12-10 22:42:55
    —— 引自第1页
  • Studying the assembly-code representation of a program is one of the most effective means for gaining an understanding of the compiler and how the generated code will run. A good strategy is to start by looking carefully at the code for the inner loops, identifying performance-reducing attributes such as excessive memory references and poor use of registers. Starting with the assembly code, we can also predict what operations will be performed in parallel and how well they will use the processor resources. As we will see, we can often determine the time (or at least a lower bound on the time) required to execute a loop by identifying critical paths, chains of data dependencies that form during repeated executions of a loop. We can then go back and modify the source code to try to steer th... (查看原文)
    Exquisiteness 2014-12-26 16:54:55
    —— 引自第476页
  • Most major compilers, including gcc, are continually being updated and improved, especially in terms of their optimization abilities. One useful strategy is to do only as much rewriting of a program as is required to get it to the point where the compiler can then generate efficient code. By this means, we avoid compromising the readability, modularity, and portability of the code as much as if we had to work with a compiler of only minimal capabilities. Again, it helps to iteratively modify the code and analyze its performance both through measurements and by examining the generated assembly code. To novice programmers, it might seem strange to keep modifying the source code in an attempt to coax the compiler into generating efficient code, but this is indeed how many high-performance ... (查看原文)
    Exquisiteness 2014-12-26 16:54:55
    —— 引自第476页
  • 1. The first step in optimizing a program is to eliminate unnecessary work, making the code perform its intended task as efficiently as possible. This includes eliminating unnecessary function calls, conditional tests, and memory references. These optimizations do not depend on any specific properties of the target machine. 2. Modern computers use sophisticated techniques to process a machine-level program, executing many instructions in parallel and possibly in a different order than they appear in the program. Programmers must understand how these processors work to be able to tune their programs for maximum speed. We present a high-level model of such a machine based on recent designs of Intel and AMD processors.We also devise a graphical data-flow notation to visualize the execution... (查看原文)
    Exquisiteness 2014-12-26 16:56:36
    —— 引自第475页
  • 1. You are going to learn practical skills such as how to avoid strange numerical errors caused by the way that computers represent numbers. 2. You will learn how to optimize your C code by using clever tricks that exploit the designs of modern processors and memory systems. 3. You will learn how the compiler implements procedure calls and how to use this knowledge to avoid the security holes from buffer overflow vulnerabilities that plague network and Internet software. 4. You will learn how to recognize and avoid the nasty errors during linking that confound the average programmer. 5. You will learn how to write your own Unix shell, your own dynamic storage allocation package, and even your own Web server. 6. You will learn the promises and pitfalls of concurrency, a topic of i... (查看原文)
    Exquisiteness 2015-01-07 16:33:23
    —— 引自第2页
  • 当值x是2的幂时,也就是,对于某个n,x=2n,我们可以很容易地将x写成十六进制形式,只要记住x的二进制表示就是1后面跟n个零。十六进制数字0代表四个二进制0.所以,对于被写成i+4j形式的n来说,其中0<=i<=3,我们可以把x写成开头的十六进制数字为1(i=0)、2(i=1)、4(i=2)或者8(i=3),后面跟随着j个十六进制的0。比如,x=2048=211,我们有n=11=3+4*2,从而得到十六进制表示0x800 (查看原文)
    豆友49796659 2015-03-30 16:16:21
    —— 引自第25页
  • People get surprisingly emotional about which byte ordering is the proper one. In fact, the terms “little endian” and “big endian” come from the book Gulliver’s Travels by Jonathan Swift, where two warring factions could not agree as to how a soft-boiled egg should be opened—by the little end or by the big. Just like the egg issue, there is no technological reason to choose one byte ordering convention over the other, and hence the arguments degenerate into bickering about socio-political issues. As long as one of the conventions is selected and adhered to consistently, the choice is arbitrary. (查看原文)
    [已注销] 2018-09-06 07:54:26
    —— 引自第40页
  • 通常,使用gets或其他任何能导致存储溢出的函数,都是不好的编程习惯。不幸的是,很多常用的库函数,包括strcpy、strcat和sprintf,都有一个属性——不需要告诉它们目标缓冲区的大小,就产生一个字节序列。这样的情况就会导致缓冲区溢出漏洞。 (查看原文)
    夏夜寂寞属壁虎 2019-10-13 17:52:11
    —— 引自第196页
  • hello.c的表示方法说明了一个基本思想:系统中所有的信息一一包括磁盘文件、内存中的程序、内存中存放的用户数据以及网络上传送的数据,都是由一串比特表示的。区分不同数据对象的唯一方法是我们读到这些数据对象时的上下文。比如,在不同的上下文中,一个同样的字节序列可能表示一个整数、浮点数、字符串或者机器指令 作为程序员,我们需要了解数字的机器表示方式,因为它们与实际的整数和实数是不同的。它们是对真值的有限近似值,有时候会有意想不到的行为表现。 (查看原文)
    [已注销] 2020-03-13 21:13:15
    —— 引自章节:1.1 信息就是位+上下文1