Skip to content

Instantly share code, notes, and snippets.

@piskvorky
Created March 20, 2014 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piskvorky/9661228 to your computer and use it in GitHub Desktop.
Save piskvorky/9661228 to your computer and use it in GitHub Desktop.
import numpy
# load a 10k x 10k array (800MB) previously stored with
# numpy.save('/tmp/x.npy', numpy.random.rand(10000, 10000))
shared = [numpy.load('/tmp/x.npy', mmap_mode='r') for _ in range(10)]
# touch all elements in all 10 copies of the same mmap'ed array
print [x.sum() for x in shared]
# ...resident/real mem spikes at 10x 800MB, nothing shared?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment