Skip to content

Allocating a lot of memory #137

@LinusU

Description

@LinusU

I'm running into some problems with memory allocations, and I think that maybe there is currently a limit of 1 MB for allocations? I'm basing this off this code here:

// Default process heap size is 1MB. It can be adjusted with linker flags, so we might
// need to revisit this. Unfortunately currently we need a process heap in place before
// we load the exe.
let size = 1 << 20;
let heap = self.new_heap(size, "process heap".into());
self.process_heap = heap;

The program I'm currently trying to run starts of by requesting 10_000_000 bytes of memory. Currently this panics, but I've changed the behavior locally to return a null pointer instead:

diff --git a/win32/system/src/heap.rs b/win32/system/src/heap.rs
index 7aa8986d..54aec4f4 100644
--- a/win32/system/src/heap.rs
+++ b/win32/system/src/heap.rs
@@ -31,7 +31,8 @@ impl Heap {
         self.freelist
             .borrow_mut()
             .alloc(mem, size)
-            .unwrap_or_else(|| panic!("heap size {:x} oom {:x}", self.size, size))
+            .unwrap_or(0)
+            // .unwrap_or_else(|| panic!("heap size {:x} oom {:x}", self.size, size))
     }
 
     pub fn size(&self, mem: Mem, addr: u32) -> u32 {

This actually lets the program continue quite a bit, starting to load in files from disk, until it hits another failed allocation of 10_008 bytes, whereupon the program handles this failure, prints an "INSUFFICIENT MEMORY" message, and shuts down...

I need to go to bed now, but any pointers that you have for how I can continue to investigate this would be much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions