Close

Overcoming python's recursion limit.

In most programming languages, you can segfault your program by going too deep in a recursive function. In CPython (the reference implementation that you are probably using), recursion is limited to a fixed number of consecutive recursive calls. The default maximum recursion can be checked by calling sys.getrecursionlimit(). On my machine, this returns 1000 for…

LD_PRELOAD hacks

This post is a bit of a departure from my normal Python evangelism. Instead, I’m going back to my C roots and exploring the somewhat mystical world of the LD_PRELOAD environment variable. TL;DR: LD_PELOAD is a (linux) variable you can set to hijack the symbol resolution order for linked libraries. First lets consider a basic…

Automatic Memoization in Python

Memoization (a key concept in dynamic programming) is a fancy word that basically means storing the results of computation and never recomputing. Instead, you simply look up the already computed value. Any pure function can be memoized. Memoization can have a dramatic affect on the runtime of algorithms which use the results of computation multiple…