Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

I haven't grokked shared memory in python yet to implement it (https://docs.python.org/3/library/multiprocessing.shared_mem...). Apparently there is also a known bug? (https://stackoverflow.com/questions/14124588/shared-memory-i...), but an improvement I'd like to learn and implement. Though the file I have is just over 1GB, so it's not prohibitive yet.

Funny thing is even though it's throwaway code, ensuring everything worked as expected felt really high-stake since a bug would mean a found key would be lost!

Edit: Also not sure if shared memory would be slower in python3 (or if it was, whether it would matter in this use-case), but an interesting thing to profile.



view as:

multiprocessing relies on the OS' fork() to share the memory transparently to the child(ren). The pages containing the memory will refer back to the same physical page until they're written to. This is what grandparent meant by "sharing memory".

multiprocessing also provides a way to access the OS' explicit shared memory usually used as an IPC mechanism.


Right, thanks for clearing that up.

multiprocessing's "shared memory" facility is for writable memory.

What I described is extremely handy as you simply move the parsing code up in the script, before your function definition, and "magically" gain memory efficiency.


Legal | privacy