-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
gc_realloc returns NULL after a few calls #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It could be that the 37k block is allocated right in the middle of the heap, and so no contiguous 38k block exists. I've added a function to the GC to print out the organisation of the heap and what is allocated/free. Call |
Note that, for your test case above, the GC can be improved to make it work. At the moment a realloc is just an alloc followed by a memcpy followed by a free. This could be changed to see if the current block can be extended in place. See line 334 of gc.c. |
but this is called first thing after running main.py, and nothing else is allocated, or maybe small objects for the strings printed are allocated which cause fragmentation :? anyway, I will try the function and send back the results. |
But you are allocating 1k, then 2k, then 3k, ..., 36k before allocating the 37k, so this will fragment the memory quite a bit. |
what if I free the memory before I look for a bigger slice, would that work :) ? oh right, need to copy it nevermind |
Yes, if you changed realloc to free+alloc, then it should work.... |
I saw the comment you mentioned in |
It should be easy to implement proper realloc: code from gc_nbytes can help determine if there are enough blocks after the current one to satisfy the allocation, and the last few lines of gc_alloc can be used to mark these blocks as used (ATB_FREE_TO_TAIL). |
I tried the same test again, and it didn't fail this time:
result after first calls to realloc:
result after realloc'ing down to 1024
|
Hi, I think there's a bug in gc_realloc, after calling it a few times it returns NULL even though there's enough memory to satisfy the request.. This is the code I'm using to test:
I call
test_realloc()
after running the main script inmain.c
This is the result:
Code is compiled with optimization and tested on discovery board... Can you confirm this ?
The text was updated successfully, but these errors were encountered: