Posts

heap

Last edited: August 8, 2025

The heap is a self-managed area of the memory.

malloc

void *malloc(size_t size);

You should pass in the number of bytes; therefore, we need to pass in the number of bytes through something like malloc(sizeof(int)*len). The memory is not cleared out.

calloc

void *calloc(size_t nmemb, size_t size);

Put the number of elements into nmemb, and the size of them into size. Stamp zeros throughout.

strdup

Deep copy a string. strlen, malloc, strcpy, retrun.

free

void free(void *ptr);

Frees whatever the pointer points to. The pointer itself (a stack variable), is not deleted and still points to the freed memory.

Heap allocator

Last edited: August 8, 2025

Upon initialization, a large contiguous block of memory is initialized as a whole and called the “heap”. If we run out of it, we double the amount of memory being allocated.

  1. handling arbitrary requests of mallocs/realloc and frees
  2. keep track of what’s been allocated and what’s free
  3. decide which segment of memory to use when fulfilling an allocating request
  4. respond quickly
  5. Return addresses that are 8-byte aligned (native types must be stored at a memory location which is a multiple of its size; otherwise bus error)

Two main goals:

Heap File Organization

Last edited: August 8, 2025

Heap File Organization is an unorganized collection of pages, which is stored in random order.

  • create
  • get
  • write
  • delete

must support iterating over all pages

Heat Equation

Last edited: August 8, 2025

see also two-dimensional heat equation the following relates to 1d

heat distributes by “diffusing”; this is heat \(u\) diffusing across a plate

\begin{equation} \pdv{u}{t} = \pdv[2]{u}{x} \end{equation}

we have, with Dirichlet Conditions:

\begin{equation} u_{k}(t,x) = \sum b_{k} e^{ - \frac{k^{2} \pi^{2}}{l^{2}} t } \sin \qty( \frac{k \pi x}{l}) \end{equation}

and with Neumann Conditions:

\begin{equation} u_{k}(t,x) = \sum b_{k} e^{ - \frac{k^{2} \pi^{2}}{l^{2}} t } \cos \qty( \frac{k \pi x}{l}) \end{equation}

with infinite boundaries:

Hello Internet

Last edited: August 8, 2025

Hello Internet is a podcast hosted by Brady Haran and CGP Grey.