CS4998: Blockchain Development Textbook
  • CS4998: Blockchain Development
  • Prerequisites
  • Introduction
    • Blockchain Theory
      • Bitcoin and the UTXO Model
      • Ethereum and the State-Based Model
    • Remix - A First Glance
    • Hello World!
      • Solidity File Structure
      • Primitive Values & Types
      • Contract Structure
      • Functions
      • Data Structures
      • Summary & Exercises
    • Hello World! Pt. 2
      • Control Flow
      • Interfaces and Inheritance
      • Constructors
      • Contract Interactions
      • Modifiers
      • Dynamic Arrays and Strings
        • Dynamic Arrays
        • Strings
      • Errors
      • Events
      • Units and Global Variables
      • Default Functions
  • Local Development
    • Node Providers
    • Interacting With On-Chain Contracts
    • Migrating to Foundry & VS Code
      • The Basics of Forge
      • Installing and Using Dependencies
      • Cast
      • Anvil
  • Understanding the EVM
    • The Ethereum Virtual Machine
      • A First Look at Computers
      • The Turing Machine
      • EVM Data Structures
      • Operation Codes (Opcodes)
      • Gas
      • Contract Compilation
      • Contract Runtime
    • Gas Optimizations
  • Yul & Advanced EVM Topics
    • Yul
    • Metamorphism
    • Bitwise Manipulations
  • Correctness
    • Security
    • Types of Testing
  • ERC Standards
    • Why ERCs?
    • ERC20
    • ERC721
    • ERC777
    • ERC1155
  • Frequently Used Smart Contracts
    • OpenZeppelin
    • Uniswap
    • Multisignature Contracts
    • AAVE/Compound
  • MEV & Advanced Blockchain Theory
    • Consensus Mechanisms vs Sybil Resistance Mechanisms
    • Maximal Extractable Value (MEV)
    • Looking Past The EVM
  • Etcetera
    • Developer Practices
    • Spring 2023 Past Resources
Powered by GitBook
On this page
  1. Introduction
  2. Hello World! Pt. 2

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.

PreviousModifiersNextDynamic Arrays

Last updated 1 year ago