本文整理汇总了Python中pypy.rlib.rmmap.mmap函数的典型用法代码示例。如果您正苦于以下问题:Python mmap函数的具体用法?Python mmap怎么用?Python mmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mmap函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: func
def func(no):
m = mmap.mmap(no, 6, access=mmap.ACCESS_READ)
m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
m.write_byte("x")
m.seek(0)
assert m.read(6) == "xoobar"
m.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_rmmap.py
示例2: func
def func():
m = mmap.mmap(-1, 1000, tagname="foo")
# same tagname, but larger size
try:
m2 = mmap.mmap(-1, 5000, tagname="foo")
m2.getitem(4500)
except WindowsError:
pass
m.close()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_rmmap.py
示例3: test_windows_crasher_1
def test_windows_crasher_1(self):
if sys.platform != "win32":
skip("Windows-only test")
m = mmap.mmap(-1, 1000, tagname="foo")
# same tagname, but larger size
try:
m2 = mmap.mmap(-1, 5000, tagname="foo")
m2.getitem(4500)
except WindowsError:
pass
m.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:12,代码来源:test_rmmap.py
示例4: do_allocation_in_far_regions
def do_allocation_in_far_regions():
"""On 32 bits: this reserves 1.25GB of address space, or 2.5GB on Linux,
which helps test this module for address values that are signed or
unsigned.
On 64-bits: reserves 10 times 2GB of address space. This should help
to find 32-vs-64-bit issues in the JIT. It is likely that objects
are further apart than 32 bits can represent; it is also possible
to hit the corner case of being precisely e.g. 2GB - 8 bytes apart.
Avoid this function if your OS reserves actual RAM from mmap() eagerly.
"""
global far_regions
if not far_regions:
from pypy.rlib import rmmap
if sys.maxint > 0x7FFFFFFF:
PIECESIZE = 0x80000000
else:
if sys.platform == 'linux':
PIECESIZE = 0x10000000
else:
PIECESIZE = 0x08000000
PIECES = 10
m = rmmap.mmap(-1, PIECES * PIECESIZE,
rmmap.MAP_PRIVATE|rmmap.MAP_ANONYMOUS|rmmap.MAP_NORESERVE,
rmmap.PROT_READ|rmmap.PROT_WRITE)
m.close = lambda : None # leak instead of giving a spurious
# error at CPython's shutdown
m._ll2ctypes_pieces = []
for i in range(PIECES):
m._ll2ctypes_pieces.append((i * PIECESIZE, (i+1) * PIECESIZE))
far_regions = m
开发者ID:gorakhargosh,项目名称:pypy,代码行数:32,代码来源:ll2ctypes.py
示例5: mmap
def mmap(space, fileno, length, flags=rmmap.MAP_SHARED,
prot=rmmap.PROT_WRITE | rmmap.PROT_READ, access=rmmap._ACCESS_DEFAULT):
try:
return space.wrap(W_MMap(space, rmmap.mmap(fileno, length,
flags, prot, access)))
except OSError, e:
raise wrap_oserror(space, e, 'w_EnvironmentError')
开发者ID:antoine1fr,项目名称:pygirl,代码行数:8,代码来源:interp_mmap.py
示例6: func
def func(no):
m = mmap.mmap(no, 7)
assert m.find("b") == 3
assert m.find("z") == -1
assert m.find("o", 5) == -1
assert m.find("ob") == 2
assert m.find("\0") == 6
m.close()
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_rmmap.py
示例7: mmap
def mmap(space, w_subtype, fileno, length, tagname="",
access=rmmap._ACCESS_DEFAULT, offset=0):
self = space.allocate_instance(W_MMap, w_subtype)
try:
W_MMap.__init__(self, space,
rmmap.mmap(fileno, length, tagname, access,
offset))
except OSError, e:
raise mmap_error(space, e)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:interp_mmap.py
示例8: test_write_readonly
def test_write_readonly(self):
if os.name == "nt":
skip("Needs PROT_READ")
f = open(self.tmpname + "l", "w+")
f.write("foobar")
f.flush()
m = mmap.mmap(f.fileno(), 6, prot=mmap.PROT_READ)
raises(RTypeError, m.write, "foo")
f.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_rmmap.py
示例9: test_write_without_protwrite
def test_write_without_protwrite(self):
if os.name == "nt":
skip("Needs PROT_WRITE")
f = open(self.tmpname + "l2", "w+")
f.write("foobar")
f.flush()
m = mmap.mmap(f.fileno(), 6, prot=~mmap.PROT_WRITE)
raises(RTypeError, m.write_byte, 'a')
raises(RTypeError, m.write, "foo")
m.close()
f.close()
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_rmmap.py
示例10: test_windows_crasher_2
def test_windows_crasher_2(self):
if sys.platform != "win32":
skip("Windows-only test")
f = open(self.tmpname + "t", "w+")
f.write("foobar")
f.flush()
f = open(self.tmpname + "t", "r+b")
m = mmap.mmap(f.fileno(), 0)
f.close()
raises(WindowsError, m.resize, 0)
raises(RValueError, m.getitem, 0)
m.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:14,代码来源:test_rmmap.py
示例11: test_find_rfind
def test_find_rfind(self):
f = open(self.tmpname + "g", "w+")
f.write("foobarfoobar\0")
f.flush()
m = mmap.mmap(f.fileno(), 13)
for s1 in range(-20, 20):
for e1 in range(-20, 20):
expected = "foobarfoobar\0".find("ob", s1, e1)
assert m.find("ob", s1, e1, False) == expected
expected = "foobarfoobar\0".rfind("ob", s1, e1)
assert m.find("ob", s1, e1, True) == expected
m.close()
f.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:15,代码来源:test_rmmap.py
注:本文中的pypy.rlib.rmmap.mmap函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论