1、1.1 A Closer Look at the Processor and Primary Storage仔细看看处理器和主存储器We have learned that all computers have similar capabilities and perform essentially the same functions, although some might be faster than others. We have also learned that a computer system has input, output, storage, and processing
2、 components; that the processor is the “intelligence” of a computer system; and that a single computer system may have several processors. We have discussed how data are represented inside a computer system in electronic states called bits. We are now ready to expose the inner workings of the nucleu
3、s of the computer system the processor. 我们已经知道,所有的计算机都具有相似的能力,并且在本质上执行相同的功能,尽管一些可能会比另一些快一点。我们也知道,一个计算机系统具有输入,输出,存储和处理部件;处理器是一个计算机系统智能核心,并且一个计算机系统可以有许多个处理器。我们已经讨论过如何在计算机系统内部,用被称作“位”的电子状态来表现数据,现在我们要弄明白计算机系统的核心,即处理器,的内在的工作方式。The internal operation of a computer is interesting, but there really is no my
4、stery to it. The mystery is in the minds of those who listen to hearsay and believe science-fiction writer. The computer is a nonthinking electronic device that has to be plugged into an electrical power source, just like a toaster or a lamp.计算机的内部操作很有意思,但确实没有什么神秘可言。所谓的神秘只是存在于那些听信传闻和相信科幻小说作家的人的意识中。计
5、算机就是一种没有思想的需要接通电源的电子设备而已,与烤面包机和台灯差不多。Literally hundreds of different types of computers are marketed by scores of manufacturers 1. The complexity of each type may vary considerably, but in the end each processor, sometimes called the central processing unit or CPU, has only two fundamental sections:
6、 the control unit and the arithmetic and logic unit. Primary storage also plays an integral part in the internal operation of a processor. These three primary storage, the control unit, and the arithmetic and logic unit work together. Lets look at their functions and the relationships between them.不
7、加夸张地讲,市场上有几百种不同类型的计算机在销售.每种电脑在复杂性上可能有很大区别,但归根结底,每种处理器,有时称为中央处理器即 cpu,只有两个基本部分:控制单元和计算逻辑单元.主内存在处理器内部操作中也是一个不可缺少的部分.这三个部件-主内存,控制单元和计算逻辑单元-一起工作.然我们看看它们(各自的)功能和它们之间的联系。Unlike magnetic secondary storage devices, such as tape and disk, primary storage has no moving parts. With no mechanical movement, data
8、 can be accessed from primary storage at electronic speeds, or close to the speed of light. Most of todays computers use DRAM (Dynamic Random-Access Memory) technology for primary storage. A state-of-the-art DRAM chip about one eighth the size of a postage stamp can store about 256,000,000 bits, or
9、over 25,600,000 characters of data!主存与其他的辅助存储器(如:磁带、硬盘)不一样的是,主存不含有运转部件。由于没有机械运转的需要,主存种数据访问可以达到电子的速度,或接近于光速。当今计算机的主存大多数使用 DRAM(动态随机存取存储器)技术。目前最新的工艺水平是:一块只有大约 1/8 张邮票大小的 DRAM 芯片却可以存储大约 256,000,000 位,约 25,6000,000 个字符的数据。Primary storage, or main memory, provides the processor with temporary storage for
10、 programs and data. All programs and data must be transferred to primary storage from an input device (such as a VDT) or from secondary storage (such as a disk) before programs can be executed or data can be processed. Primary storage space is always at a premium; therefore, after a program has been
11、 executed, the storage space it occupied is reallocated to another program awaiting execution.主存储器,也就是说内存,用于为处理器暂时存放程序和数据。所有的程序和数据在被操作之前必须从输入设备(如 VDT)或者辅助存储器转存到主存储器中。主存储器存储容量通常是相当有限的,因此,在一个程序执行结束,它所占用的存储空间必须被重新分配给其它正在等待执行操作的程序。Figure 1-1 illustrates how all input/output (I/O) is “read to” or “writte
12、n from” primary storage. In the figure, an inquiry (input) is made on a VDT. The inquiry, in the form of a message, is routed to primary storage over a channel (such as a coaxial cable). The message is interpreted, and the processor initiates action to retrieve the appropriate program and data from
13、secondary storage 3.The program and data are “loaded”, or moves, to primary storage from secondary storage. This is a nondestructive read process. That is, the program and data that are read reside in both primary storage (temporarily) and secondary storage (permanently). The data are manipulated ac
14、cording to program instructions, and a report is written from primary storage to a printer.图 1-1 描述了输入/输出设备与主存储器间的读和写过程。在图中,VDT 发出一个输入请求,请求是以消息模式通过通道(如同轴电缆)发送到主存储器。这个查询被解释,处理器发起操作从辅助存储器中调用合适的程序和数据。程序和数据从辅助存储器传送到主存储器中,这是一个非破坏性的读取过程,也就是说,程序和数据同时存在于主存(临时保存)和辅助存储器(永久保存)中。根据程序指令的指示,处理器对数据进行操作,并从主存传送一份报告到
15、打印机。A program instruction or a piece of data is stored in a specific primary storage location called an address. Addresses permit program instructions and data to be located, accessed, and processed. The content of each address is constantly changing as different programs are executed and new data a
16、re processed.程序指令和数据是存储在主存中一个特殊的位置,称为地址空间。通过地址空间可以实现计算机对程序指令和数据的定位、访问和处理。地址空间的内容是经常变化的,这是由于计算机一直在执行不同的程序和数据。Another name for primary storage is random-access memory, or RAM. A special type of primary storage, called read-only memory (ROM), cannot be altered by the programmer. The contents of ROM are
17、 “hard-wired” (designed into the logic of the memory chip) by the manufacturer and can be “read only”. When you turn on a microcomputer system, a program in ROM automatically readies the computer system for use. Then the ROM program produces the initial display screen prompt.主存储器也称为随机存取存储器,或 RAM。还有一
18、种特殊的主存储器,称为只读存储器(ROM) ,这种存储器不能被程序更改存放的内容。ROM 的内容是被生产商通过硬件电路写入的,并且不能被重写。当你启动计算机,ROM 中的一个程序会自动就绪等待计算机系统的调用,然后在显示器中显示开机提示。A variation of ROM is programmable read-only memory (PROM). PROM is ROM into which you, the user, can load “read-only” programs and data. Once a program is loaded to PROM, it is sel
19、dom, if ever, changed 4. However, if you need to be able to revise the contents of PROM, there is EPROM, erasable PROM. Before a write operation, all the storage cells must be erased to the same initial state.可编程只读存储器(PROM)是另一种 ROM,它可以载入只读的程序和数据,一旦载入,将不再改变。然而,若果你需要去修正 PROM 的内容,可以使用可擦可编程只读存储器。EPROM 在
20、进行一次写操作之前,所有的存储单元必须被还原为同一初始状态。A more attractive form of read-mostly memory is electrically erasable programmable read-only memory (EEPROM). It can be written into at any time without erasing prior contents; only the byte or bytes addressed are updated.一种更吸引人的可改写只读存储器是电可擦除可编程只读存储器 (EEPROM)。它可以在任何时候写入
21、,而且不会擦除以前的内容;只会更新被寻址的字节。The EEPROM combines the advantage of nonvolatility with the flexibility of being updatable in place 6, using ordinary bus control, address, and data lines.电可擦可编程存储器把非易失性优点和可更新、需要更新的地方的灵活性结合起来,修改时使用普通的总线控制线、地址线和数据线。Another form of semiconductor memory is flash memory (so named
22、 because of the speed). Flash memory is intermediate between EPROM and EEPROM in both cost and functionality. Like EEPROM, flash memory uses an electrical erasing technology. An entire flash memory can be erased in one or a few seconds, which is much faster than EPROM. In addition, it is possible to
23、 erase just blocks of memory rather than an entire chip. However, flash memory does not provide byte-level erasure 7. Like EPROM, flash memory uses only one transistor per bit, and so achieves the high density of EPROM.另一种半导体记忆体是闪存(意味着速度快) 。闪存在性价比上处于 EPROM 和 EEPROM 之间,它使用电擦写技术。整个闪存的内容可以在一到几秒内被清除,这是远
24、快于 EPROM 的。另外,它还可以对部分记忆块而不是整个存储器进行清除。然而,闪存并不提供字节级的擦除。像 EPROM,闪存只使用一个晶体管每比特,因此可以实现高密度的 EPROM。Cache MemoryProgram and data are loaded to RAM from secondary storage because the time required to access a program instruction or piece of data from RAM is significantly less than from secondary storage. Tho
25、usands of instructions or pieces of data can be accessed from RAM in the time it would take to access a single piece of data from disk storage 8. RAM is essentially a high-speed holding area for data and programs. In fact, nothing really happens in a computer system until the program instructions an
26、d data are moved to the processor. This transfer of instructions and data to the processor can be time-consuming, even at microsecond speeds. To facilitate an even faster transfer of instructions and data to the processor, most computers are designed with cache memory. Cache memory is employed by co
27、mputer designers to increase the computer system throughput (the rate at which work is performed).程序和数据从辅助存储器装载到 RAM 中是因为对 RAM 中的程序指令和数据的访问时间要明显的少于从辅助存储器访问。数以千条的指令和数据能被访问而只需花费从硬盘访问一次数据的时间。RAM 是数据和程序的重要的高速存放区,事实上,计算机系统不会进行任何操作直到程序指令被传入处理器进行执行,这种指令和数据的传输是需要花费时间的,即使传输速度已经是以纳秒来计算了。为了能更快速的传输指令和数据,大多数计算机设
28、计使用高速缓存。计算机设计者使用高速缓存来提高计算机系统的总处理能力(工作效率) 。Like RAM, cache is a high-speed holding area for program instructions and data. However, cache memory uses SRAM (Static RAM) technology that is about 10 times faster than RAM and about 100 times more expensive. With only a fraction of the capacity of RAM, ca
29、che memory holds only those instructions and data that are likely to be needed next by the processor. Two types of cache memory appear widely in computers. The first is referred to as internal cache and is built into the CPU chip. The second, external cache, is located on chips placed close to the C
30、PU chip. A computer can have several different levels of cache memory. Level 1 cache is virtually always built into the chip. Level 2 cache used to be external cache but is now typically also built into the CPU like level 1 cache.和 RAM 一样,高速缓存也是程序指令和数据的高速存储区。然而,高速缓存使用静态 RAM技术,这种技术比 RAM 在速度上要高出 10 倍,
31、价格上高出 100 倍。cache 只保存内存中那一小部分最有可能被处理器执行的指令和数据。两种类型的 cache 广泛应用于计算机,第一种被植入 cpu 中的叫做内部高速存储,第二种是外部高速存储,它位于那些靠近 cpu 的芯片中。一台计算机可以拥有几个不同级别的高速缓存。一级缓存实际上总是植入芯片中,二级缓存过去常常作为外部高速缓存,但是现在也像一级缓存植入 cpu 内部。3.2 C+和面向对象的程序设计一些面向对象的程序设计概念在语言间渗透。例如微软 Quick Pascal 是允许使用对象的第一批语言中的一个。C+有什么使得它是一种适合于开发面向对象程序的语言?如同先前所提到的,答案是
32、类(class)数据类型。给该语言建立对象之能力的是建立在 C 结构类型之上的 C+类(class)类型。还有,C+把另外几个特性引入面向对象的程序设计,这些特性并不包含在简单地利用对象的其他一些语言中。C+ 的优点包括强类型、运算符重载和较少地强调预处理。的确你能使用其他一些产品和采用其他一些语言来进行面向对象的程序设计,但是采用 C+的众多好处是显著的。这是为面向对象的程序设计而设计的语言,并非(现有语言的)式样翻新。面向对象的程序设计是一种程序设计技术,使得你能把一些概念看作各种各样的对象。通过使用对象,你能表示要被执行的任务、它们之间的相互作用和必须观察的某些给定的条件。一种数据结构经
33、常形成某个对象的基础;因此,在 C 或 C+中,结构类型能形成某种基本对象。与对象的通信,如前提到的,能通过使用消息来完成。消息的使用类似于在面向过程的程序中对函数的调用。当某对象收到一个消息时,包含在该对象内的一些方法作出响应。 方法 类似于面向过程程序设计的函数。然而,方法是对象的一部分。C+的类是对 C 和 C+结构类型的扩充,并且形成了面向对象程序设计所需要的抽象数据类型。类能包含紧密相关的一些条目,它们共享一些属性。更正式地说,对象只不过是类的实例。最终,应该出现包含很多对象类型的类库,你能使用这些对象类型的实例去拼合程序代码。在你更详细地考察这些术语之前,一个好的主意是熟悉与 C+
34、和面向对象程序设计相关的另外几个概念,如同下面几节所述的。封装封装 指的是每个对象把它的成员数据和成员函数(方法)组合成单个结构的方式。图3-1 举例说明了你如何能组合数据域和方法以建立对象。数据域 方法 图 3-1 为建立对象而组合的数据域和方法典型地,一个对象的描述是一个 C+类的一部分, 且包括对该对象内部结构的描述、该对象如何与其他对象相关,以及把该对象的功能细节和该类的外部相隔离的某种形式的保护。C+类结构做到了所有这些。在一个 C+类中,你使用私有的、公共的和/或受保护的描述符来控制对象的功能细节。在面向对象的程序设计中, 公共 (public)部分一般用于接口信息(方法) ,使得
35、该类可在各应用中重用。如果数据或方法被包含在公共部分,它们在该类外部也可用。类的 私有 部分把数据或方法的可用性局限于该类本身。包含数据或方法的 受保护 部分被局限于该类和任何派生子类。类层次结构C+类实际上用作创建对象的模板或模式。从类描述形成的对象都是该类的 实例 。开发类层次结构是可能的,其中有一个主类和几个子类。在 C+中, 做这事的基础是 派生类 。父类表示更一般化的任务,而派生子类执行一些特定的任务。例如,早先讨论的林肯类也许包含整个林肯系列公共的数据和方法,诸如引擎、检测仪表、电池、制动能力和操纵。从父类派生的子类,诸如 Tour Car、Mark 和 Continental 可
36、能包含该类专用的一些款项。例如,1995 Continental 是该系列中唯一具有主动悬架系统的汽车。继承面向对象程序设计中的 继承 使得一个类能继承某对象类的一些性质。父类用作派生类的模式,且能以几种方式被改变(在下一章中你将了解成员函数能被重载、新的成员函数能被添加,并且成员存取特权能被改变) 。如果某个对象从单个父类继承其属性,称为 单继承 。如果某个对象从多个父类继承属性,便称为 多继承 。继承是一个重要概念,因为它使得无须对代码做大的改变就能重用类定义。继承鼓励重用代码,因为子类是对父类的扩充。多态性与类层次结构相关的另一个重要的面向对象概念是公共消息能被发送到诸父类对象和所有派生
37、子类对象。按正式的术语,这称为 多态性 。成员函数成员函数数据数据 成员函数成员函数成员函数数据数据 成员函数多态性使每个子类对象能以一种对其定义来说适当的方式对消息格式作出响应。试设想收集数据的一个类层次结构。父类可能负责收集某个个体的姓名、社会安全号、职业和雇佣年数,那末你能使用子类来决定根据职业将添加什么附加信息。一种情况,一个管理职位会包括年薪,而另一种情况,销售员职位会包括小时工资和回扣信息。因此,父类收集一切子类公共的通用信息,而子类收集与特定工作描述相关的附加信息。多态性使得公共的数据收集消息能被发送到每个类。父类和子类两者都以对该消息是恰当的方式作出响应。多态性促进现有代码的可
38、扩充性。虚函数多态性赋予对象以当对象的精确类型还未知时响应来自例行程序之消息的能力。在C+中这能力是 迟绑定 的结果。使用迟绑定,地址在运行时刻动态地确定,而不是如同传统的编译型语言在编译时刻静态地确定。这静态的(固定的)方法往往称为 早绑定 。函数名被替换为存储地址。你使用 虚函数 来完成迟绑定。在随后的派生类将通过重定义函数之实现而重载该函数时,在父类中定义虚函数。当你使用虚函数时,消息不是直接传给对象,而是作为指向对象的指针传送。虚函数利用了地址信息表, 该表在运行时刻使用构造符而被初始化。一个构造符每当创建它的类的一个对象时被调用。这里构造符的工作是把虚函数与地址信息表链接,在编译运转
39、期间虚函数的地址是未知的;相反,给出的是(在运行时刻确定的)地址表中将包含该函数(入口)地址的位置。3.4 JavaScript 教程Java is designed to meet the challenges of application development in the context of heterogeneous, network-wide distributed environments. Paramount among these challenges is secure delivery of applications that consume the minimum o
40、f system resources, can run on any hardware and software platform, and can be extended dynamically.Java 是为了解决在复杂的、大规模分布式网络环境下开发应用程序的挑战而设计的。其中最大的一个挑战是确保交付的程序:占用最少的系统资源,并且能在任何硬件、软件平台下运行,能被动态扩展。Java originated as part of a research project to develop advanced software for a wide variety of network devi
41、ces and embedded systems. The goal was to develop a small, reliable, portable, distributed, real-time operating platform. When the project started, C+ was the language of choice. But over time the difficulties encountered with C+ grew to the point where the problems could best be addressed by creati
42、ng an entirely new language platform. Design an architecture decisions drew from a variety of language such as Eiffel, SmallTalk, Objective, C, and Cedar/Mesa. The result is a language platform that has proven ideal for developing secure, distributed, network based end-user applications in environme
43、nts ranging from network-embedded devices to the World-Wide-Web an the desktop.Java 最初只是一个为各种网络和嵌入式设备而研究的软件系统的一部分,这个系统的目标是一个小的、可信赖的、可移植的,分布式的、实时的平台。最开始 C+语言是这个平台的首选。但随着时间的推移,C+出现了很多问题,有必要开发一个全新的语言平台。我们根据 Eiffel, SmallTalk, Objective, C, and Cedar/Mesa 等语言来做出决策,结果是开发出了一个理想的、能在从嵌入式网络设备到万维网到桌面等各种环境下方便的
44、开发安全的、分布的、基于网络的应用程序的平台。The design requirements of Java are driven by the nature of the computing environments in which software must be deployed.Java 的设计要求是由软件所部署的计算环境的本质决定的.The massive growth of the Internet and the World-Wide Web leads us to a completely new way of looking at development and distr
45、ibution of software. To live in the world of electronic commerce and distribution, Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks.互联网和万维网的快速发展带领我们用新的眼光去看待开发和发布软件。在电子商务的时代,Java 必须具有开发
46、安全性、高效性、健壮的、大众的、能在多平台和多样化、分布式网络运行的程序。Operating on multiple platforms in heterogeneous networks invalidates the traditional schemes of binary distribution , release, upgrade, patch, and so on. To survive in this jungle, java must be architecture neutral, portable, and dynamically adaptable.为了能在异构网络的多
47、个平台上执行二进制发布、升级、修补等计划的环境中发展,Java必须是总体结构不带偏向性的、可移植的、且能动态地自适应的。The java system that emerged to meet there needs in simple, so it can be easily programmed by most developers; familiar, so that current developers can easily learn java; object oriented ,to take advantage of modern software development met
48、hodologies and to fit into distributed client-server application; multithreaded, for high performance in applications that need to perform multiple concurrent activities , such as multimedia; and interpreted ,for maximum portability and dynamic capabilities.Java 系统的出现使得这些需求变得简单,所以可以很容易的被大多数开发人员所使用;大
49、众的,所以现在的开发人员可以很容易的学习 Java;面对对象的,利用现代软件开发方法的优势以适应分布式客户端-服务器应用程序;多线程的,用于高性能的执行多个并发活动,如多媒体;解释型的,为了最大的可移植性和动态能力。Together, the above requirements comprise quite a collection of buzzwords, so lets examine some of them and their respective benefits before going on.总的来说,上述包括相当多的专业术语,所以在继续之前先让我们来认识一下它们以及它们所带来的的各种好处。Whats completely new is the manner in which java and its run-time system have combined them to produce a flexible and powerful programming system.Java 和它在运行时的系统能包含有良好的操作性以及强大的编译设计系统是一种全新的方式。Developing your applications using
Copyright © 2018-2021 Wenke99.com All rights reserved
工信部备案号:浙ICP备20026746号-2
公安局备案号:浙公网安备33038302330469号
本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。