



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Spring 2003 CS 403 Class Notes (^) Page 1
Spring 2003 CS 403 Class Notes (^) Page 2
Spring 2003 CS 403 Class Notes (^) Page 4
Fundamental Pointer Operations
Spring 2003 CS 403 Class Notes (^) Page 5
Implicit vs. Explicit Dereferencing
C++ (Explicit Deference):
class Node{ public: int x; Node *next; };
Node n; n = new Node; (n).x = 3; n->x = 3;
Ada (Implicit deref for recs):
type Node is record x: integer; next: access Node; end Node;
n: access Node; n = new Node; n.x = 3
Spring 2003 CS 403 Class Notes (^) Page 7
void foo(int &x){ int y = 0; x = y; y = x; }
Spring 2003 CS 403 Class Notes (^) Page 8
int n; int *a; int b[10]; a = b; n = a[3]; n = *(a + 3); n = b[3]; n = *(b + 3);
Spring 2003 CS 403 Class Notes (^) Page 10
Spring 2003 CS 403 Class Notes (^) Page 11
void main(void){ int *x, *y; x = new int; y = new int; *y = 3; x = y; }
Spring 2003 CS 403 Class Notes (^) Page 19
What Garbage Collection Will Do
void foo(void){ Node *head; //manufacture linked list pointed to by //head }
In this example, garbage collection will walk through the entire list and free up every node (once head is dead) No explicit list traversal to free up memory is needed Java supports this approach and provides automatic garbage collection – it does not provide a “delete” operator.
Spring 2003 CS 403 Class Notes (^) Page 20
Approaches to Garbage Collection
Spring 2003 CS 403 Class Notes (^) Page 22
Spring 2003 CS 403 Class Notes (^) Page 23
Spring 2003 CS 403 Class Notes (^) Page 25
Spring 2003 CS 403 Class Notes (^) Page 26
Problems with this Version
Spring 2003 CS 403 Class Notes (^) Page 27