Weird Python Integers Part II: Constants in Bytecode
Related
More from Kate Murphy
After investigating the CRuby source code for hash tables, my interest was piqued, and I decided to look into another hash table implementation before leaving Recurse Center. I chose to investigate Lua because the hash table is the central abstraction of the language. I don’t actually know Lua, but luckily I spent most of my investigation in a...
Note: This is all Python 3 code. Other versions of Python may handle subprocesses and bytearrays differently. A Git bomb is a compact repository that explodes to consume extreme size on disk and in memory. Read more about them in the original git bomb post. This post walks through some code to create them. A full script to create them is...
If you are an adventurous sort (and can handle a potential reboot) I invite you to clone this tiny repo: $ git clone https://github.com/Katee/git-bomb.git Were you able to clone it? Unless you have quite a lot of memory (both RAM and storage) git was killed, ran out of memory, or you had to reboot. Why is this? It is a perfectly formed repo made...
Note: All code was run using Ruby MRI 2.4.1 and is not guaranteed to behave the same in other implementations (JRuby, mruby, etc). Also you probably don’t want to do this in a real project. Like (every?) user of Ruby I constantly use the built-in Hash class. I’ve made my own classes usable as keys and know that there are multiple equality...
Note: all of this code was run on my machine using Python 3.6.1. Not everything will work the same if you test using Python 2. >>> a = 42 >>> b = 42 >>> a is b True >>> a = 316 >>> b = 316 >>> a is b False That is suprising! It turns out that all “small integers” with the same value point to the same memory. We can use the Python built-in...