c语言program,c_program_1C语言

这篇博客探讨了网络通信的基础,从早期的资源共享到现在的互联网应用。提到了以太网、局域网和广域网的基本概念,以及网络协议如TCP/IP在数据传输中的重要性。还讨论了网络性能的影响因素,包括协议处理、内存速度和总线速率,并通过实例比较了不同网络技术的性能。最后,指出了网络设计中的一些挑战和限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《c_program_1C语言》由会员分享,可在线阅读,更多相关《c_program_1C语言(32页珍藏版)》请在人人文库网上搜索。

1、CS61CAnatomy of I/O Devices: Networks Lecture 14,March 5, 1999 Dave Patterson (http.cs.berkeley.edu/patterson) www-inst.eecs.berkeley.edu/cs61c/schedule.html,Review 1/2,Operating System started as shared I/O library Support for OS abstraction: Kernel/User bit, stacked KU bits, syscall MIPS follows c。

2、oprocessor abstraction to add resources, instructions for OS Interrupt control: Interrupt Enable bit, stacked IE bits, Interrupt Priority Levels, Interrupt Mask Re-entrant via restricting int. to higher priority DMA to accelerate data movement,Outline,Buses Why Networks? A Simple Example: Derive Net。

3、work Basics Protocol, Ethernet Administrivia, “Computers in the News” Internetworking, Protocol Suites, TCP/IP Performance Pitfalls Conclusion,Recall : 5 components of any Computer,Processor (active),Computer,Control (“brain”),Datapath (“brawn”),Memory (passive) (where programs, data live when runni。

4、ng),Devices,Input,Output,Keyboard, Mouse,Display, Printer,Disk, Network,Connecting to Networks (and Other I/O),Bus - shared medium of communication that can connect to many devices Hierarchy of Buses in a PC,Buses in a PC,Data rates Memory: 100 MHz, 8 bytes 800 MB/s (peak) PCI: 33 MHz, 4 bytes wide 。

5、132 MB/s (peak) SCSI: “Ultra2” (40 MHz), “Wide” (2 bytes) 80 MB/s (peak),Why Networks?,Originally sharing I/O devices between computers (e.g., printers) Then Communicating between computers (e.g, file transfer protocol) Then Communicating between people (e.g., email) Then Communicating between netwo。

6、rks of computers Internet, WWW,Types of Networks,Local Area Network (Ethernet) Inside a building: Up to 1 km (peak) Data Rate: 10 Mbits/sec, 100 Mbits/sec,1000 Mbits/sec Run, installed by network administrators Wide Area Network Across a continent (10km to 10000 km) (peak) Data Rate: 1.5 Mbits/sec t。

7、o 2500 Mbits/sec Run, installed by telephone companies,ABCs of Networks: 2 Computers,Starting Point: Send bits between 2 computers Queue (First In First Out) on each end Can send both ways (“Full Duplex”) Information sent called a “message” Note: Messages also called packets,A Simple Example: 2 Comp。

8、uters,What is Message Format? (Similar in idea to Instruction Format) Fixed size? Number bits?,0: Please send data from address in your memory 1: Packet contains data corresponding to request,Header(Trailer): information to deliver message Payload: data in message (1 word above),Questions About Simp。

9、le Example,What if more than 2 computers want to communicate? Need computer “address field” in packet to know which computer should receive it (destination), and to which computer it came from for reply (source),Questions About Simple Example,What if message is garbled in transit? Add redundant info。

10、rmation that is checked when message arrives to be sure it is OK 8-bit sum of other bytes: called “Check sum”; upon arrival compare check sum to sum of rest of information in message,Questions About Simple Example,What if message never arrives? If tell sender it has arrived (and tell receiver reply 。

11、has arrived), can resend upon failure Dont discard message until get “ACK”; (Also, if check sum fails, dont send ACK),Observations About Simple Example,Simple questions such as those above lead to more complex procedures to send/receive message and more complex message formats Protocol: algorithm fo。

12、r properly sending and receiving messages (packets),Ethernet Packet Format,Preamble,Dest Addr,Src Addr,Length of Data2 Bytes,Data,Check,Preamble to recognize beginning of packet Unique Address per Ethernet Network Interface Card so can just plug in if not, delete message (sender resends when timer e。

13、xpires) 1: If OK, OS copies data to user address space, Enabling technologies: SW standards that allow reliable communications without reliable networks Hierarchy of SW layers, giving each layer responsibility for portion of overall communications task, called protocol families or protocol suites Ab。

14、straction to cope with complexity of communication vs. Abstraction for complexity of computation,Protocol for Network of Networks,Transmission Control Protocol/Internet Protocol (TCP/IP) This protocol family is the basis of the Internet, a WAN protocol IP makes best effort to deliver TCP guarantees 。

15、delivery TCP/IP so popular it is used even when communicating locally: even across homogeneous LAN,FTP From Stanford to Berkeley,BARRNet is WAN for Bay Area T3 is 45 Mbit/s leased line (WAN); FDDI is 100 Mbit/s LAN IP sets up connection, TCP sends file,T3,FDDI,FDDI,Ethernet,Ethernet,Ethernet,Henness。

16、y,Patterson,FDDI,Protocol Family Concept,Message,Message,Message,Protocol Family Concept,Key to protocol families is that communication occurs logically at the same level of the protocol, called peer-to-peer, but is implemented via services at the lower level Danger is each level lower performance i。

17、f family is implemented as hierarchy (e.g., multiple check sums),TCP/IP packet, Ethernet packet, protocols,Application sends message,TCP breaks into 64KB segments, adds 20B header,IP adds 20B header, sends to network,If Ethernet, broken into 1500B packets with headers, trailers (24B),All Headers, tr。

18、ailers have length field, destination, .,Shared vs. Switched Based Networks,Shared Media vs. Switched: pairs communicate at same time: “point-to-point” connections Aggregate BW in switched network is many times shared point-to-point faster since no arbitration, simpler interface,Example of Network P。

19、erformance,Compare Ethernet, ATM sending a message with a 5 MB payload Time to send message: Overhead + Size/Data Rate Ethernet Overhead: 500 microseconds BW is 1.25 Mbyte/sec ATM Overhead: 600 microseconds BW is 10 Mbyte/sec Transmission time = Overhead + Size/(Data Rate),Example of Network Perform。

20、ance,Compare Ethernet (10 Mbit/sec), ATM (800 Mbit/sec) sending a message with a 250 Byte payload Time to send message: Overhead + Size/Data Rate Ethernet Overhead: 460 microseconds BW is 1.25 Mbyte/sec Time = 460 + 250/1.25 = 660 usecs ATM Overhead: 630 microseconds BW is 10 Mbyte/sec Time = 630 + 。

21、250/10 = 655 microseconds,Limits to Performance of Networks,Layers of protocol Processor speed for protocol processing Memory speed for transferring messages Bus speed for connecting to computer Sharing of Network by multiple computers,I/O Pitfall: Relying on Peak Data Rates,Using the peak transfer 。

22、rate of a portion of the I/O system to make performance projections or performance comparisons Peak bandwidth measurements often based on unrealistic assumptions about system or unattainable because of other system limitations In example, Peak Bandwidth FDDI vs.10 Mbit Ethernet = 10:1, but delivered。

23、 BW ratio (due to software overhead) is 1.01:1 Peak PCI BW is 132 MByte/sec, but combined with memory often 80 MB/s,Network Media (if time),“And in Conclusion.” 1/1,Protocol suites allow heterogeneous networking Another use of principle of abstraction Protocols operation in presence of failures Standardization key for LAN, WAN Integrated circuit revolutionizing network switches as well as processors Switch just a specialized computer High bandwidth networks with slow SW overheads dont deliver their promise Next: Anatomy of disks, RAID。

1. 避免将多个类放在一个文件里面。 2. 一个文件应该只有一个命名空间,避免将多个命名空间放在同一个文件里面。 3. 一个文件最好不要超过500行的代码(不包括机器产生的代码)。 4. 一个方法的代码长度最好不要超过25行。 5. 避免方法中有超过5个参数的情况。使用结构来传递多个参数。 6. 每行代码不要超过80个字符。 7. 不要手工的修改机器产生的代码。 a) 如果需要编辑机器产生的代码,编辑格式和风格要符合该编码标准。 b) Use partial classes whenever possible to factor out the maintained portions. 8. 避免利用注释解释显而易见的代码。 a) 代码应该可以自解释。好的代码由可读的变量和方法命名因此不需要注释。 9. Document only operational assumptions, algorithm insights and so on. 10. 避免使用方法级的文档。 a) 使用扩展的API文档说明之。 b) 只有在该方法需要被其他的开发者使用的时候才使用方法级的注释。(在C#中就是///) 11. 不要硬编码数字的值,总是使用构造函数设定其值。 12. 只有是自然结构才能直接使用const,比如一个星期的天数。 13. 避免在只读的变量上使用const。如果想实现只读,可以直接使用readonly。 public class MyClass { public readonly int Number; public MyClass(int someValue) { Number = someValue; } public const int DaysInWeek = 7; } 14. 每个假设必须使用Assert检查 a) 平均每15行要有一次检查(Assert) using System.Diagnostics; object GetObject() {…} object obj = GetObject(); Debug.Assert(obj != null); 15. 代码的每一行都应该通过白盒方式的测试。 16. 只抛出已经显示处理的异常。 17. 在捕获(catch)语句的抛出异常子句中(throw),总是抛出原始异常维护原始错误的堆栈分配。 catch(Exception exception) { MessageBox.Show(exception.Message); throw ; //和throw exception一样。 } 18. 避免方法的返回值是错误代码。 19. 尽量避免定义自定义异常类。 20. 当需要定义自定义的异常时: a) 自定义异常要继承于ApplicationException。 b) 提供自定义的序列化功能。 21. 避免在单个程序集里使用多个Main方法。 22. 只对外公布必要的操作,其他的则为internal。 23. Avoid friend assemblies, as it increases inter-assembly coupling. 24. Avoid code that relies on an assembly running from a particular location. 25. 使应用程序集尽量为最小化代码(EXE客户程序)。使用类库来替换包含的商务逻辑。 26. 避免给枚举变量提供显式的值。 //正确方法 public enum Color { Red,Green,Blue } //避免 public enum Color { Red = 1,Green = 2,Blue = 3 } 27. 避免指定特殊类型的枚举变量。 //避免 public enum Color : long { Red,Green,Blue } 28. 即使if语句只有一句,也要将if语句的内容用大括号扩起来。 29. 避免使用trinary条件操作符。 30. 避免在条件语句中调用返回bool值的函数。可以使用局部变量并检查这些局部变量。 bool IsEverythingOK() {…} //避免 if (IsEverythingOK ()) {…} //替换方案 bool ok = IsEverythingOK(); if (ok) {…} 31. 总是使用基于0开始的数组。 32. 在循环中总是显式的初始化引用类型的数组。 public class MyClass {} MyClass[] array = new MyClass[100]; for(int index = 0; index < array.Length; index++) { array[index] = new MyClass(); } 33. 不要提供public 和 protected的成员变量,使用属性代替他们。 34. 避免在继承中使用new而使用override替换。 35. 在不是sealed的类中总是将public 和 protected的方法标记成virtual的。 36. 除非使用interop(COM+ 或其他的dll)代码否则不要使用不安全的代码(unsafe code)。 37. 避免显示的转换,使用as操作符进行兼容类型的转换。 Dog dog = new GermanShepherd(); GermanShepherd shepherd = dog as GermanShepherd; if (shepherd != null ) {…} 38. 当类成员包括委托的时候 a) Copy a delegate to a local variable before publishing to avoid concurrency race condition. b) 在调用委托之前一定要检查它是否为null public class MySource { public event EventHandler MyEvent; public void FireEvent() { EventHandler temp = MyEvent; if(temp != null ) { temp(this,EventArgs.Empty); } } } 39. 不要提供公共的事件成员变量,使用事件访问器替换这些变量。 public class MySource { MyDelegate m_SomeEvent ; public event MyDelegate SomeEvent { add { m_SomeEvent += value; } remove { m_SomeEvent -= value; } } } 40. 使用一个事件帮助类来公布事件的定义。 41. 总是使用接口。 42. 类和接口中的方法和属性至少为2:1的比例。 43. 避免一个接口中只有一个成员。 44. 尽量使每个接口中包含3-5个成员。 45. 接口中的成员不应该超过20个。 a) 实际情况可能限制为12个 46. 避免接口成员中包含事件。 47. 避免使用抽象方法而使用接口替换。 48. 在类层次中显示接口。 49. 推荐使用显式的接口实现。 50. 从不假设一个类型兼容一个接口。Defensively query for that interface. SomeType obj1; IMyInterface obj2; /* 假设已有代码初始化过obj1,接下来 */ obj2 = obj1 as IMyInterface; if (obj2 != null) { obj2.Method1(); } else { //处理错误 } 51. 表现给最终用户的字符串不要使用硬编码而要使用资源文件替换之。 52. 不要硬编码可能更改的基于配置的字符串,比如连接字符串。 53. 当需要构建长的字符串的时候,使用StringBuilder不要使用string 54. 避免在结构里面提供方法。 a) 建议使用参数化构造函数 b) 可以重裁操作符 55. 总是要给静态变量提供静态构造函数。 56. 能使用早期绑定就不要使用后期绑定。 57. 使用应用程序的日志和跟踪。 58. 除非在不完全的switch语句中否则不要使用goto语句。 59. 在switch语句中总是要有default子句来显示信息(Assert)。 int number = SomeMethod(); switch(number) { case 1: Trace.WriteLine("Case 1:"); break; case 2: Trace.WriteLine("Case 2:"); break; default : Debug.Assert(false); break; } 60. 除非在构造函数中调用其他构造函数否则不要使用this指针。 // 正确使用this的例子 public class MyClass { public MyClass(string message ) {} public MyClass() : this("hello") {} } 61. 除非你想重写子类中存在名称冲突的成员或者调用基类的构造函数否则不要使用base来访问基类的成员。 // 正确使用base的例子 public class Dog { public Dog(string name) {} virtual public void Bark( int howLong) {} } public class GermanShepherd : Dog { public GermanShe pherd(string name): base (name) {} override public void Bark(int howLong) { base .Bark(howLong); } } 62. 基于模板的时候要实现Dispose()和Finalize()两个方法。 63. 通常情况下避免有从System.Object转换来和由System.Object转换去的代码,而使用强制转换或者as操作符替换。 class SomeClass {} //避免: class MyClass { void SomeMethod(T t) { object temp = t; SomeClass obj = (SomeClass)temp; } } // 正确: class MyClass where T : SomeClass { void SomeMethod(T t) { SomeClass obj = t; } } 64. 在一般情况下不要定影有限制符的接口。接口的限制级别通常可以用强类型来替换之。 public class Customer {…} //避免: public interface IList where T : Customer {…} //正确: public interface ICustomerList : IList {…} 65. 不确定在接口内的具体方法的限制条件。 66. 总是选择使用C#内置(一般的generics)的数据结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值