Memory growth ignores the requested size #48

Closed
opened 2026-09-25 11:31:02 +00:00 by Furkan · 1 comment
main() {
	_ := new(byte, 1)

	b := new(byte, 5000000)

	b[4999999] = 42

	assert b[4999999] == 42
}

exit status 0xc0000005

I asked an llm this and it gave me this fix seems to be working, maybe useful idk

--- a/lib/mem/alloc.q
+++ b/lib/mem/alloc.q
@@ -3,9 +3,10 @@ alloc(length uint) -> (buffer ![]byte) {
 
 	if heap.current + aligned > heap.max {
 		size := (heap.max - heap.min + 32) * 2 as uint
+		needed := (aligned + 32 + (pageSize - 1)) & -pageSize
 
-		if size < pageSize {
-			size = (aligned + (pageSize - 1)) & -pageSize
+		if size < needed {
+			size = needed
 		}
 
 		x := rawAlloc(size)
``` main() { _ := new(byte, 1) b := new(byte, 5000000) b[4999999] = 42 assert b[4999999] == 42 } ``` exit status 0xc0000005 I asked an llm this and it gave me this fix seems to be working, maybe useful idk ``` --- a/lib/mem/alloc.q +++ b/lib/mem/alloc.q @@ -3,9 +3,10 @@ alloc(length uint) -> (buffer ![]byte) { if heap.current + aligned > heap.max { size := (heap.max - heap.min + 32) * 2 as uint + needed := (aligned + 32 + (pageSize - 1)) & -pageSize - if size < pageSize { - size = (aligned + (pageSize - 1)) & -pageSize + if size < needed { + size = needed } x := rawAlloc(size) ```
ed self-assigned this 2026-09-25 14:33:44 +00:00
ed changed title from Bug: Mem Allocator [Windows] to Memory growth ignores the requested size 2026-09-25 15:29:09 +00:00
Owner

Fixed in 3fdf471603.

Fixed in https://git.urbach.dev/cli/q/commit/3fdf471603adb45e855cb97cd4fb8150f2dfa6a4.
ed closed this issue 2026-09-26 16:45:35 +00:00
Sign in to join this conversation.
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cli/q#48
No description provided.