CITS2002 Systems Programming  
next CITS2002 CITS2002 schedule  

Dynamic data structures

Initially, we focused on scalar and array variables, whose size is known at compile-time.

More recently, we've focused on arrays of values, whose required size was only known at run-time.

In the case of dynamic arrays we've used C99 functions such as:

malloc(), calloc(), realloc(), and free()
to manage the required storage for us.

An extension to this idea is the use of dynamic data structures - collections of data whose required size is not known until run-time. Again, we'll use C99's standard memory allocation functions whenever we require more memory.

However, unlike our use of realloc() to grow (or shrink) a single data structure (there, an array), we'll see two significant differences:

  • we'll manage a complete data structure by allocating and deallocating its "pieces", and
  • we'll keep all of the "pieces" linked together by including, in each piece, a "link" to other pieces.

To implement these ideas in C99, we'll develop data structures that contain pointers to other data structures.

All code examples in this lecture are available from here:


CITS2002 Systems Programming, Lecture 20, p1, 8th October 2019.