can somebody please explain how does 0 influence mmap in python in this case:
mmap.mmap(0 , 256, "some tag")
I thought that I always need to transfer file descriptor rather than 0, so why zero?
From reading CPython 2.7 source code, it seems that on Windows, specifying fileno = 0 has the same effect as specifying fileno = -1, where the latter means "map anonymous memory".
Only -1 is accepted on Unix: on my 64-bit Ubuntu box with Python 2.6.5, mmap.mmap(0, 256) fails with errno=19 (No such device) and mmap.mmap(-1, 256) works fine.
Bottom line: fileno = 0 is a non-portable Windows-only variant of fileno = -1. It may get deprecated (there's even a commented-out warning in the code to that effect).
P.S. The CPython source file in question is Modules/mmapmodule.c.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With