View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

W. Owen Redwood

Coweb Assignment 3:

Collection Classes:
1) How do OrderedCollection and Set differ?

First off, Sets contain no duplicates; whereas OrderedCollection allows for duplicate values. Sets are traversed using a hash table for fast indexing. OrderedCollections are arrays that grow accordingly when data is added to it.

2) How do OrderedCollection and Array differ? Why would you use one over the other?

OrderedCollection is basically an Array, but grows as necessary. Array should be used whenever the size of the objects to be stored is fixed, while OrderedCollection should be used when the future capacity is not known.

3) How do you use a Dictionary? Why is accessing a Dictionary so fast?

A Dictionary is used like a hash table by looking up keys to quickly access certain values. This function allows you to directly access the desired value and bypass most other data.

Garbage Collection
A) What are the advantages and disadvantages to using garbage collection?

The advantages to GC are memory leak-prevention and optimized memory allocation.
The real only disadvantage to GC is that it weighs down on your processor performance.

B) Explain how reference counting works. Include an example.

Reference counting is the method in which GC keeps count of all the references to an object. When an object has no references, this counter will reach 0. When this happens GC automatically deletes the object from memory as it is no longer being used.
pointer1 = memory block # 45
pointer2 = memory block # 33
pointer1 = pointer 2

C) Explain how mark and sweep works. Include an example.

Mark and sweep use boolean values to keep track of whether an object is being referenced or not. It is very similar to reference counting, as when an object is marked 'false' it is garbage collected.
pointer1 = memory block #45
pointer2 = memory block #33
pointer 1 = pointer 2

D) What problems of garbage collection do generational scavenging and “stop and copy” address? How do they address them?

Unlike reference counting and mark and sweep, generational scavenging partitions the memory used by the program into different segments. Each segment is checked with different frequency than the others. The most checked segment contains the commonly used variables, and the least checked segment contains the rarely used variables. This whole process is much easier on the processor than the other GC methods.

Stop and copy fixes data fragmentation by copying accessable data over to other segments. The downside to this is that it uses twice the amount of memory, but it does indeed avoid data fragmentation
======================
CoWeb Assignment 1:

Class-Based Inheritance (1 point):
What is a class?

A: A class is a blueprint of how to create an object. The class defines the object's messages, properties, and behaviors.

What is an instance?

A: An instance is a unique manifestation of a class. An instance draws all its behaviors and messages from the class, but holds its own data that makes it distinct from any other instance.

How do the two relate?

A: An object is an instance of a class. Metaphorically speaking, the class is the blueprint and the instance is the building created using that blueprint.

In Smalltalk, what is the difference between class variables and instance variables?

A: Class variables are shared across all instances of the class, much like variables that have the static modifier in java. Class variables also begin with a capital letter. All instances of a class will have the same number of instance variables; however, the data within the instance variables is different and distinct (although not neccessarily, as you could have multiple instances of a class all with the exact same variable data). Therefore, instance variables are unique per instance, as data can vary from instance to instance.

In Smalltalk, what is the difference between class and instance methods.

A: Instance methods are limited to the instance itself, and cannot reach beyond that scope. Whereas, Class methods pertain to the class itself, modifying the class variables and whatnot. Class methods also begin with a capital letter.
Writing Code (1 point):

Fibbonacci: n
(n 0) ifTrue [self error: 'Invalid input: The Nth term cannot be negative'].
(n = 0) ifTrue [^1].
(n = 1) ifTrue [^1].
(n > 1) ifTrue [^(self Fibbonacci: (n - 1) + self Fibbonacci: (n - 2))].

Links to this Page