Created
February 16, 2012 02:21
-
-
Save redbo/1841051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mmap | |
import ctypes | |
class Record(ctypes.Structure): | |
_fields_ = [('index', ctypes.c_uint64), | |
('key', ctypes.c_char * 256)] | |
RECORD_COUNT = 256 | |
storage_mem = mmap.mmap(-1, RECORD_COUNT * ctypes.sizeof(Record)) | |
array = (Record * RECORD_COUNT).from_buffer(storage_mem) | |
for i in xrange(RECORD_COUNT): | |
array[i].index = i | |
array[i].key = 'item ' + str(i) | |
for i in xrange(RECORD_COUNT): | |
assert array[i].index == i | |
assert array[i].key == 'item ' + str(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out https://gist.github.com/53405d856137175aa59d
Using c_wchar_p in the Array causes the child processes to use about a quarter the amount of memory that the parent process uses (if they read all of the data or a large chunk).
Using Record in the Array causes the child processes to use FAR less memory.....WTF.