Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Engineering 3156 19-Nov-01 #21: Language II Phil Gross.

Similar presentations


Presentation on theme: "Software Engineering 3156 19-Nov-01 #21: Language II Phil Gross."— Presentation transcript:

1 Software Engineering 3156 19-Nov-01 #21: Language II Phil Gross

2 2 Administrivia Calendar tweak Wednesday class Research Fair – Nov 30 th, 10am-4pm – http://www.cs.columbia.edu/acm/research http://www.cs.columbia.edu/acm/research Intro to Perl & CGI – Nov 20 th, 6-8pm

3 3 Implementation Notes Chat – Formal/modal – Log messages – Should have distinguished… ChangeOther for bots – MapDelta? – RequestActorChange?

4 4 And More… Death sequence – Attacked with death=true – KickGame – DeletedObject – If actor, LDAP deletion “Raw” sockets: anyone going to be using these? Integration is … interesting

5 5 Advanced Programming You can’t take it Because Prof. Schulzrinne is taking hints from our syllabus So, going to try to cover as much of his stuff as possible http://www.cs.columbia.edu/~hgs/teaching/ap/

6 6 Review of C Manual compilation and linking – Multiple.o files manually linked into executable Statements and operators the same as Java Fewer datatypes – Everything is really some size of int or float – Including, in particular, booleans and chars – Very weak typing

7 7 EZ Aggregation struct point { int x; int y; }; struct point pt; pt.x = 3; pt.y = 4;

8 8 Pointers Integers that represent a machine address Typed, sorta – Pointer to int, pointer to char Declare, dereference with * – int *p; Define with & – int q; p = &q; /* p contains q’s address */

9 9 More Pointers int x = 7; ip = &x; printf(“%d\n”, *ip); Prints 7 *ip = 9 /* assignment */ printf(“%d\n”, x); Prints 9

10 10 Pointer Arithmetic If ip == 4C84, after ip++, ip == 4C88 – assuming ints are four bytes This is the meaning of the “type” of a pointer Doesn’t really have arrays, just pointers int a[7]; a ≡ &a[0] ++a ≡ &a[1]

11 11 C Likes Pointers No strings, just char arrays terminated with 0 Char pointers flying all over the place in a C program Pointers = modifiable args Note three meanings of 0 – Falseness – End-of-String char – Null pointer (guaranteed invalid)

12 12 C is Minimal i.e. nearly nonexistent runtime services No array/pointer bounds checking – Except for processor halt if you try to dereference 0 Carefree casting – Reinterpret bits as you please: You’re the boss! No exception mechanism Certainly no garbage collection

13 13 Memory management Everything is primitive by default If you want a block of bytes, just ask void *malloc(int size) int *myString = (int *)malloc(1024 * sizeof(int)); myString is all mine, until I free it – Exactly once, please And if I double-free or don’t free? – I’m F*(&%$!ed

14 14 Pointers Not Null-initialized char *cp; Copy a bunch of stuff to cp Perfectly legal Totally undefined Disaster Need to allocate space to cp

15 15 “Right” way char *cp = (char *) malloc (SOMESIZE); Now I can “safely” copy stuff to cp Why all the quotes? What if SOMESIZE isn’t big enough…

16 16 Systems Programming Unix, Windows (and JVM) all written in C/C++ Couldn’t write a JVM for a bare system in Java Need access to underlying system resources Located at particular memory locations Operating system provides (very) basic services System calls

17 17 System Calls Man page section 2, not 3 That is the sum total of what an OS does – It usually also comes with a bunch of software Systems programming involves dealing directly with the system calls, or just above

18 18 Typical System Calls File access Time and date Process management Signals Networking Security

19 19 File I/O open, creat, close read, write – Pure byte-oriented

20 20 Unix and Devices Everything’s a file Devices are “special files” Character or block oriented Character devs include some weird things – Mice – Audio Block devices are storage Mknod

21 21 Filesystems Sorta part of the OS Usually abstracted and modularized Primitive version has one filesystem per “volume” Unix model has “mount points” Hard links vs. soft links

22 22 Special Filesystems /proc – Virtual filesystem – Access to all kinds of information – Originally processes NFS – Network filesystem – RPC based Journalling Filesystems

23 23 Processes The fork model Copy on write Vfork

24 24 Virtual Memory and Paging Memory allocated by “pages” When full, some pages are copied to disk Replacement targets picked by some strategy – What strategy? Can leverage this yourself with “memory mapped files”

25 25 IPC Message/queue Shared memory/semaphore

26 26 Signals “software interrupts” Asynchronous model Not as nice as threads…

27 27 Sockets Way ugly Highly confusing I have examples…

28 28 C++ C with classes And function overloading And operator overloading And an amazing standard library


Download ppt "Software Engineering 3156 19-Nov-01 #21: Language II Phil Gross."

Similar presentations


Ads by Google