DOC PREVIEW
Columbia COMS 3156 - OS, Language, Design Patterns

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Software Engineering 315626-Nov-01#22: OS, Language, Design PatternsPhil Gross2Administrivia!Research Fair–Nov 30th, 10am-4pm–http://www.cs.columbia.edu/acm/research!Advanced Perl–Networking and OO–Tuesday, Nov 27th, 6-8pm!JSP and Servlets–Wednesday, Nov 28th, 6-8pm3Systems 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 calls24System Calls!Man page section 2, not 3–Or weirder sections, particularly for Solaris!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 above5Typical System Calls!File access !Time and date!Process management !Signals !Networking!Security6File I/O!open, creat, close!read, write–Pure byte-oriented37Unix 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!Mknod8Filesystems!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 links9Special Filesystems!/proc–Virtual filesystem–Access to all kinds of information–Originally processes!NFS–Network filesystem–RPC based!Journalling Filesystems410Processes!The fork model!Copy on write!Vfork!Most processes are sleeping/waiting at any given time!Scheduler in kernel picks from among the ready processes for the next time slice11Virtual Memory and Paging!Every program allocated large flat memory space, mapped to real memory!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”12IPC!Message/queue–Every process has its own little mailbox!Shared memory/semaphore–We see the same memory–We have these things called semaphores that we can use as locks to ensure no simultaneous writes–Locking sequence with multiple readers and writers?513Signals!“software interrupts”!Asynchronous model!When signal arrives, current task stops and “signal handler” starts executing!Not as nice as threads…14Sockets!Way ugly!Highly confusing!Janak wrote a nice, heavily commented example15Socket call!Reserves a name, basically!Supports one of a number of Protocol Domains!Usually PF_INET for Internet Protocol communication!Also a Type, usually SOCK_STREAM (=TCP) or SOCK_DGRAM (=UDP)!Plus a specific protocol (rare)616System Call Notes!All three parameters are untyped!Int, int, and int!Better put them in the right sequence…!Linux supports a bunch more protocols than Solaris!But Solaris TCP/IP support is among the best17Bind and Listen!Bind–Says on what port and interface to listen–Note delightful steps to define an address!Listen–Says that this will be a server socket–Defines pending queue size18Accept!Actually gives us the socket!Can then read() and write() bytes719C++!C with classes!And function overloading!And operator overloading!And an amazing standard library20Inheritance in C++!Can be public, protected or private!class A : public class B { … }–Inheritance type becomes visibility of class B public members!Has multiple inheritance–class A : public class B, private class C { … }–Useful for “mixins”–Beware the Death Diamond21Polymorphism in C++!Methods not late-binding by default!To get polymorphic behavior, must explicitly label methods with “virtual”–And only pass objects by reference or pointer–Not value!Extra “VPTR” added to class!Should also make destructor virtual822When CTOR Allocates Memory…!You must–Free the memory in the destructor–Define your own copy constructor–Define your own assignment operator!Default Copy/Assignment is bitwise–Pointers are copied (“shallow” copy)!If a temp copy of your object is made, then freed, your memory will be deallocated!23Design Patterns!Seminal book is Design Patterns: Elements of Reusable Object-Oriented Software, by Gamma, Helm, Johnson, and Vlissides, 1995–Usually referred to, even in formal bibliographies, as the Gang of Four book, or just Gamma!Owes a debt to A Pattern Language: Towns/Buildings/Construction, by Christopher Alexander, 197724What is a Design Pattern?!From Alexander: “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice”!Generally presented as Name, Problem, Solution, Consequences925What is a Design Pattern cont.!Not data structures, and not extremely domain specific!“Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context”!Generally involve designing with more flexibility and indirection than you might otherwise initially use26Strategy Pattern!Instead of hardcoding algorithm, create an interface!Allow runtime selection of concrete implementation!More elegant than if-then sequences!My dispatcher is related to this27Iterator Pattern!The classic: (almost) fully absorbed into Java and C++!Abstract pointer-like object that can iterate through any data structure with a consistent interface!C++ has a beautiful version!Java is half-baked!Beware of updates while iterating!1028Flyweight Pattern!Dealing with hordes of objects!We want every character in our document to be an object–Normally far too expensive!Instantiate only one object per character and share!Characters point to format objects to minimize state29Singleton Pattern!Ensure only one of a particular type of object!class Singleton {!public: static Singleton* instance();!protected: Singleton();!private: static Singleton* _instance;!};30Factory Method!Provides an abstract interface for constructors!Allows subclasses to substitute their own constructors!Typical Pattern technique of substituting a more flexible “loose coupling” for built in OO rigidity!Java: java.net.SocketImplFactory1131Chain of Responsibility!Decouple sender and receiver!Ask for help on screen widget–May be handled by element itself–Or parent–Or great-grandparent!Use instances of HelpHandler to find successor in


View Full Document

Columbia COMS 3156 - OS, Language, Design Patterns

Download OS, Language, Design Patterns
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OS, Language, Design Patterns and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OS, Language, Design Patterns 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?