Posts

Showing posts from May, 2022

mpool

Image
An overhead free aligned memory allocator (Well, almost overhead free)      I designed this memory allocator for a Linux device driver I wrote 20 years ago .  It has the property that if you ask for 64 bytes you get a 64 byte aligned block; if you ask for 128, you get a 128 byte aligned block; and so on.  The other nice thing about it is that it automatically defragments, which is to say that if, for example, a 128 byte aligned 128 byte block is free then it can be allocated as a 128 byte block, even if it one or both halves have previously been allocated as 64 byte blocks and later freed. The key to the design is the data structure.  Each free block has a 64 byte header consisting of 16 pointers (I wrote this for a 32-bit architecture, although it could easily be ported).  For this reason 64 bytes is the smallest block size that can be allocated.  The pointers are all either NULL or point to another free block of the same size, forming a 16-ary tree of equal-sized free blocks.  At th

Everything, Everywhere, All At Once

Image
What's going on right now, 70,000 light years away on the nearest galaxy to our own, Canis Major?  Or put it another way, if we're at $x = y = z = t = 0$, what's happening at $y = z = t = 0$ and $x$ = 70,000 light years? According to Einstein's special theory of relativity it depends who you ask.  The most natural coordinates to use depend on your inertial frame.  Sitting in frame $S$, I may use the coordinates $x,y,z,t$ but someone in frame $S'$ would need to use $x',y',z',t'$ in order to observe the universe operating according to the same physical laws.  To make it more concrete, imagine $S$ and $S'$ share their $y$ and $z$ axes, and $S'$ is moving at velocity $v$ along the $x$ axis of $S$.  In this case the transform for converting between the two reference frames is $$ \begin{align} x' &= \frac{x - vt}{\sqrt{1-\frac{v^2}{c^2}}} \\ y' &= y \\ z' &= z \\ t' &= \frac{t - \frac{vx}{c^2}}{\sqrt{1-\frac{v^2}{c^