11"""Module containnig a memory memory manager which provides a sliding window on a number of memory mapped files"""
22from util import (
3- MemoryWindow ,
4- MappedRegion ,
5- MappedRegionList ,
3+ MapWindow ,
4+ MapRegion ,
5+ MapRegionList ,
66 is_64_bit ,
77 )
88
99from exc import RegionCollectionError
1010from weakref import ref
1111import sys
1212
13- __all__ = ["MappedMemoryManager " ]
13+ __all__ = ["SlidingWindowMapManager " ]
1414#{ Utilities
1515
1616#}END utilities
1717
18- class MemoryCursor (object ):
18+ class SlidingCursor (object ):
1919 """Pointer into the mapped region of the memory manager, keeping the current window
2020 alive until it is destroyed.
2121
22- Cursors should not be created manually, but are instead returned by the MappedMemoryManager """
22+ Cursors should not be created manually, but are instead returned by the SlidingWindowMapManager """
2323 __slots__ = (
2424 '_manager' , # the manger keeping all file regions
2525 '_rlist' , # a regions list with regions for our file
@@ -29,8 +29,8 @@ class MemoryCursor(object):
2929 )
3030
3131 #{ Configuration
32- MemoryWindowCls = MemoryWindow
33- MappedRegionCls = MappedRegion
32+ MapWindowCls = MapWindow
33+ MapRegionCls = MapRegion
3434 #} END configuration
3535
3636 def __init__ (self , manager = None , regions = None ):
@@ -133,9 +133,9 @@ def use_region(self, offset, size, flags = 0, _is_recursive=False):
133133 #END while bisecting
134134
135135 if existing_region is None :
136- left = self .MemoryWindowCls (0 , 0 )
137- mid = self .MemoryWindowCls (offset , size )
138- right = self .MemoryWindowCls (self .file_size (), 0 )
136+ left = self .MapWindowCls (0 , 0 )
137+ mid = self .MapWindowCls (offset , size )
138+ right = self .MapWindowCls (self .file_size (), 0 )
139139
140140 # we want to honor the max memory size, and assure we have anough
141141 # memory available
@@ -166,13 +166,13 @@ def use_region(self, offset, size, flags = 0, _is_recursive=False):
166166 # possible mapping
167167 if insert_pos == 0 :
168168 if len_regions :
169- right = self .MemoryWindowCls .from_region (a [insert_pos ])
169+ right = self .MapWindowCls .from_region (a [insert_pos ])
170170 #END adjust right side
171171 else :
172172 if insert_pos != len_regions :
173- right = self .MemoryWindowCls .from_region (a [insert_pos ])
173+ right = self .MapWindowCls .from_region (a [insert_pos ])
174174 # END adjust right window
175- left = self .MemoryWindowCls .from_region (a [insert_pos - 1 ])
175+ left = self .MapWindowCls .from_region (a [insert_pos - 1 ])
176176 #END adjust surrounding windows
177177
178178 mid .extend_left_to (left , window_size )
@@ -189,7 +189,7 @@ def use_region(self, offset, size, flags = 0, _is_recursive=False):
189189 if man ._handle_count >= man ._max_handle_count :
190190 raise Exception
191191 #END assert own imposed max file handles
192- self ._region = self .MappedRegionCls (a .path_or_fd (), mid .ofs , mid .size , flags )
192+ self ._region = self .MapRegionCls (a .path_or_fd (), mid .ofs , mid .size , flags )
193193 except Exception :
194194 # apparently we are out of system resources or hit a limit
195195 # As many more operations are likely to fail in that condition (
@@ -301,7 +301,7 @@ def fd(self):
301301 #} END interface
302302
303303
304- class MappedMemoryManager (object ):
304+ class SlidingWindowMapManager (object ):
305305 """Maintains a list of ranges of mapped memory regions in one or more files and allows to easily
306306 obtain additional regions assuring there is no overlap.
307307 Once a certain memory limit is reached globally, or if there cannot be more open file handles
@@ -315,7 +315,7 @@ class MappedMemoryManager(object):
315315 space is full."""
316316
317317 __slots__ = [
318- '_fdict' , # mapping of path -> MappedRegionList
318+ '_fdict' , # mapping of path -> MapRegionList
319319 '_window_size' , # maximum size of a window
320320 '_max_memory_size' , # maximum amount ofmemory we may allocate
321321 '_max_handle_count' , # maximum amount of handles to keep open
@@ -324,7 +324,7 @@ class MappedMemoryManager(object):
324324 ]
325325
326326 #{ Configuration
327- MappedRegionListCls = MappedRegionList
327+ MapRegionListCls = MapRegionList
328328 #} END configuration
329329
330330 _MB_in_bytes = 1024 * 1024
@@ -411,10 +411,10 @@ def make_cursor(self, path_or_fd):
411411 prevents the file to be opened again just for the purpose of mapping it."""
412412 regions = self ._fdict .get (path_or_fd )
413413 if regions is None :
414- regions = self .MappedRegionListCls (path_or_fd )
414+ regions = self .MapRegionListCls (path_or_fd )
415415 self ._fdict [path_or_fd ] = regions
416416 # END obtain region for path
417- return MemoryCursor (self , regions )
417+ return SlidingCursor (self , regions )
418418
419419 def collect (self ):
420420 """Collect all available free-to-collect mapped regions
0 commit comments