Pointer Variables and Dynamic Allocation

Pointers: The Problem

Pointers - The Problem

The Solution


Introduction: Box Example

Java References: Class Box

Start with type Box

Now Introduce Type BoxPtr

Refer to the Entire Box, with .all

Some Things Never Change ...

Some Strong Typing

Can .all can be Omitted?

Sometimes .all is Required

Type BoxPtr: Another Example

Some Practice and Strong Typing

One Type in Java vs Two in Ada

Java and the Object Referenced

Java Comparison: Two Types vs One

Java Terminology: Two Types vs One

Dynamic Structures and Linked Lists

Problem and Solution

Dynamic Stacks and Queues

Types for Linked Structures - Version 1

Types for Linked Structures - Version 2

Making a List

Dynamic Stacks and Queues

A Dynamic Stack

An Empty Stack

A Dynamic Queue

Code for Dynamic Stacks and Queues

Class Exercises for Linked Structures

Problems with Pointers - And Solutions

Three Possible Kinds of Errors

Error 1: Null Pointers

Error 2: Garbage

Avoid Garbage with Explicit Deallocation of Memory

Error 3: Dangling References


Dangling References

Dangling References and Reallocated Memory

Dangling References and Reallocation of Different Types

Avoiding Dangling References

Summary of Errors

Memory Organization

Memory Management and Kinds of Variables

Memory Organization - Three Areas of Memory

Memory Organization Diagram

Looking at Memory Addresses

Printing Addresses

Modular Types

Modular Types and Addreses

Converting Pointers to Our Address Type

Pointing to Variables on the Stack

Pointers in Other Languages

Pointers in Other Languages

More Discussion of Pointers

Memory and Addresses

Comparison of Java References and Ada Pointers

Why Pointers/References

Why Pointers