Dynamic Arrays and Strings

Advanced Data Structures

As it will become clear later on, working with constant-size data structures allows us to organize values in an efficient matter. However, perhaps the biggest drawback of constant-size data structures is that we cannot adjust the size to meet our demands.

Consider a painter that wishes to keep track of the paintings he produces in a list (we assume each painting can be represented by an arbitrary integer).

contract Painter {

    uint N = 100;
    uint[N] paintings;


Although we can change N to be whatever size we want it to be (at contract creation time), its pretty obvious to see that when the painter paints his N + 1 painting, there will not be enough space in the paintings array to store his painting.

Dynamic types allow us to create data structures whose size is not fixed. Furthermore, learning about dynamic types will allow us to focus our attention towards strings.

Last updated