View
214
Download
0
Embed Size (px)
Citation preview
2
Administrivia
Calendar tweak Wednesday class Research Fair
– Nov 30th, 10am-4pm– http://www.cs.columbia.edu/acm/research
Intro to Perl & CGI– Nov 20th, 6-8pm
3
Implementation Notes
Chat– Formal/modal– Log messages– Should have distinguished…
ChangeOther for bots– MapDelta?– RequestActorChange?
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
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
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
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
More Pointers
int x = 7;
ip = &x;
printf(“%d\n”, *ip); Prints 7
*ip = 9 /* assignment */
printf(“%d\n”, x); Prints 9
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
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
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
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
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
“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
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
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
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
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
Special Filesystems
/proc– Virtual filesystem– Access to all kinds of information– Originally processes
NFS– Network filesystem– RPC based
Journalling Filesystems
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”