heap
Last edited: August 8, 2025The 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, 2025Upon 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.
- handling arbitrary requests of mallocs/realloc and frees
- keep track of what’s been allocated and what’s free
- decide which segment of memory to use when fulfilling an allocating request
- respond quickly
- 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, 2025Heap 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, 2025see 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, 2025Hello Internet is a podcast hosted by Brady Haran and CGP Grey.