1
0
mirror of https://github.com/Escartem/AnimeWwise.git synced 2026-06-05 07:50:23 +08:00

lot of fixes and progress

This commit is contained in:
Escartem
2024-07-23 13:01:57 +02:00
parent 990ffb8901
commit 6472ce2b01
4 changed files with 210 additions and 114 deletions

25
allocator.py Normal file
View File

@@ -0,0 +1,25 @@
# memory manager to prevent redundant calls to files and save up disk usage
# may cause massive ram usage if we input too many pck at once, fix required
import os
import mmap
class Allocator:
def __init__(self):
self.files = {}
def load_file(self, path):
filename = os.path.basename(path)
with open(path, "r+b") as f:
mmap_object = mmap.mmap(f.fileno(), 0)
self.files[filename] = mmap_object,
def read_at(self, file, offset, size):
data = self.files[file][offset:offset+size]
return data
def free_mem(self):
for file in list(self.files.keys()):
self.files[file].close()
self.files.clear()