Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using mmap in python

Tags:

python

mmap

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?

like image 476
yeap Avatar asked Aug 18 '26 23:08

yeap


1 Answers

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.

like image 86
NPE Avatar answered Aug 20 '26 12:08

NPE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!