[英]Why is mmap in Python implemented as shared library?
I'm new to python. 我是python的新手。 But I'm curious that why the mmap in python is implemented as shared library, while not a .py file.
但是我很好奇为什么python中的mmap是作为共享库而不是.py文件实现的。 This makes my IDE can't index the source codes of mmap.
这使我的IDE无法索引mmap的源代码。
Here is the output in my python3.2 environment(ubuntu 12.04): 这是我的python3.2环境(ubuntu 12.04)中的输出:
markz@markz-hp6200:~$ python3.2
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mmap
>>> print(mmap.__file__)
/usr/lib/python3.2/lib-dynload/mmap.cpython-32mu.so
>>>
mmap
uses OS-specific facilities such as the mmap
function on Linux (and MapViewOfFile
function on Windows). mmap
使用特定于操作系统的功能,例如Linux上的mmap
函数(Windows上的MapViewOfFile
函数)。 These are not directly available in Python (eg through the os
module), so at least part of the mmap
module has to be written in C to call those functions. 这些在Python中不是直接可用的(例如,通过
os
模块),因此必须用C编写至少部分mmap
模块才能调用这些函数。
This particular use has nothing to do with efficiency -- the module had to be written in C (or use ctypes
) in order to use this OS functionality. 这种特殊用途与效率无关-为了使用此OS功能,必须用C编写模块(或使用
ctypes
)。
There are lots of things in the standard library of Cpython written in C. Other examples are itertools
, parts of csv
( _csv
), parts of collections
( _collections
)... I would think that one of the main reasons is for efficiency. 用C语言编写的Cpython标准库中有很多东西。其他示例是
itertools
, csv
( _csv
), collections
( _collections
)...我认为主要原因之一是效率。 The developers decided they could get the code to go faster if they used a compiled language. 开发人员认为,如果使用编译语言,他们可以使代码运行得更快。
mmap
is implemented in C, not python. mmap
是用C实现的,而不是python。 An extension module implemented in C has to be shared library. 用C实现的扩展模块必须是共享库。
Why? 为什么? In this case, probably because you can't implement the functionality without access to C. The modules which are implemented in python are implemented using the functionality provided in other modules.
在这种情况下,可能是因为无法访问C无法实现功能。使用其他模块提供的功能来实现以python实现的模块。 But the mmap functionality is implemented by calling the C standard library functions.
但是mmap功能是通过调用C标准库函数来实现的。 There is no way it could be a python file.
不可能是python文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.