Bitpath

Lesson 1 · Unit 03

Allocation

What values cost, and streaming instead of building lists

12 exercisesabout 3 min

What you practise

  • What objects cost, garbage collection in outline and its pauses, streaming with generators or iterators against building the whole list

Try a question from this lesson

Pick one

To sum the squares of 1 to 10,000,000, version A builds a list of all the squares and then sums it. Version B adds each square to a running total. What differs?

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Lists and streams

A list holds all of its items at once. Memory grows with the number of items.

A stream (a generator or iterator) produces one item at a time, on request. Memory stays flat: one item, plus whatever running answer you keep.

Use a stream when each item can be handled and then forgotten: totals, counts, filters, the largest so far.

The limits: a stream can be read only once, and you cannot index into it or ask for its length.

10 more exercises in the app

  • 2× type the answer
  • 5× multiple choice
  • 1× true or false
  • 1× match the pairs
  • 1× fill the blanks

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy