Skip to main content
Engineering LibreTexts

14.1: The Block Store

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The notion of external memory includes a large number of possible different devices, each of which has its own block size and is accessed with its own collection of system calls. To simplify the exposition of this chapter so that we can focus on the common ideas, we encapsulate external memory devices with an object called a BlockStore. A BlockStore stores a collection of memory blocks, each of size \(B\). Each block is uniquely identified by its integer index. A BlockStore supports these operations:

    1. \(\mathtt{readBlock(i)}\): Return the contents of the block whose index is \(\mathtt{i}\).
    2. \(\mathtt{writeBlock(i,b)}\): Write contents of \(\mathtt{b}\) to the block whose index is \(\mathtt{i}\).
    3. \(\mathtt{placeBlock(b)}\): Return a new index and store the contents of \(\mathtt{b}\) at this index.
    4. \(\mathtt{freeBlock(i)}\): Free the block whose index is \(\mathtt{i}\). This indicates that the contents of this block are no longer used so the external memory allocated by this block may be reused.

    The easiest way to imagine a BlockStore is to imagine it as storing a file on disk that is partitioned into blocks, each containing \(B\) bytes. In this way, \(\mathtt{readBlock(i)}\) and \(\mathtt{writeBlock(i,b)}\) simply read and write bytes \(\mathtt{i}B,\ldots,(\mathtt{i}+1)B-1\) of this file. In addition, a simple BlockStore could keep a free list of blocks that are available for use. Blocks freed with \(\mathtt{freeBlock(i)}\) are added to the free list. In this way, \(\mathtt{placeBlock(b)}\) can use a block from the free list or, if none is available, append a new block to the end of the file.

    This page titled 14.1: The Block Store is shared under a CC BY license and was authored, remixed, and/or curated by Pat Morin (Athabasca University Press) .

    • Was this article helpful?