Search code examples
pythonmemoryunpack

Python MemoryError on struct.unpack


I'm getting a MemoryError when trying to unpack data that I read from a file. I want to be able to read every single byte that's why I'm unpacking it. When I unpack just 1 byte it works but when i want to read the whole dump (total_size) it gives the error. I have no idea what to do.

def read_memory(self, mem_file, address, byte_count):
        mem_file.seek(address)
        data = mem_file.read(byte_count)
        return data

memory_dump = self.read_memory(mem_file, start_addr, total_size)
unpacked = struct.unpack("{}B".format(total_size), memory_dump) # MemoryError

How can I fix this?


Solution

  • Seems like I didn't have enough RAM