|
5 | 5 | MappedRegionList, |
6 | 6 | ) |
7 | 7 |
|
| 8 | +from exc import RegionCollectionError |
8 | 9 | from weakref import proxy |
9 | 10 |
|
10 | 11 | __all__ = ["MappedMemoryManager"] |
@@ -45,7 +46,7 @@ def _destroy(self): |
45 | 46 | num_clients = self._rlist.client_count() - 2 |
46 | 47 | if num_clients == 0 and len(self._rlist) == 0: |
47 | 48 | # Free all resources associated with the mapped file |
48 | | - self._manager._files.pop(self._rlist.path()) |
| 49 | + self._manager._fdict.pop(self._rlist.path()) |
49 | 50 | #END remove regions list from manager |
50 | 51 | #END handle regions |
51 | 52 |
|
@@ -82,6 +83,7 @@ def use_region(self, offset, size): |
82 | 83 | This is not the case if the mapping failed becaues we reached the end of the file |
83 | 84 | :note: The size actually mapped may be smaller than the given size. If that is the case, |
84 | 85 | either the file has reached its end, or the map was created between two existing regions""" |
| 86 | + |
85 | 87 |
|
86 | 88 | def unuse_region(self): |
87 | 89 | """Unuse the ucrrent region. Does nothing if we have no current region |
@@ -146,5 +148,19 @@ class MappedMemoryManager(object): |
146 | 148 | a safe amount of memory already, which would possibly cause memory allocations to fail as our address |
147 | 149 | space is full.""" |
148 | 150 |
|
149 | | - __slots__ = tuple() |
150 | | - |
| 151 | + __slots__ = [ |
| 152 | + '_fdict', # mapping of path -> MappedRegionList |
| 153 | + '_max_window_size', # maximum size of a window |
| 154 | + '_max_memory_size', # maximum amount ofmemory we may allocate |
| 155 | + '_max_handles', # maximum amount of handles to keep open |
| 156 | + '_memory_size', # currently allocated memory size |
| 157 | + '_handle_count', # amount of currently allocated file handles |
| 158 | + ] |
| 159 | + |
| 160 | + def _collect_one_lru_region(self, size): |
| 161 | + """Unmap the region which was least-recently used and has no client |
| 162 | + :param size: size of the region we want to map next (assuming its not already mapped partially or full |
| 163 | + if 0, we try to free any available region |
| 164 | + :raise RegionCollectionError: |
| 165 | + :todo: implement a case where all unusued regions are discarded efficiently. Currently its only brute force""" |
| 166 | + |
0 commit comments