I have been working with mem_Free function to deallocate memory blocks created with file_LoadFunction and mem_Alloc functions. Allocations and deallocations all work fine, but according to the manual, the mem_Free function should return TRUE if successfull and FALSE if deallocation fails. According to my tests, this is not the case and the function returns values 0, 2, 3 or 4. Also, if the function is suppose to fail, there is a change in the memory heap.
If I do everything correctly, all the functions work fine, but especially if I do something wrong, the replies are a bit beyond a simple TRUE and FALSE. Can you explain what is the meaning of these return values? Also, if there is a problem, the function is able to detect it and returns 3 instead of 2, but still changes some memory?
Also, what will happen, if I try to deallocate a static function (not dynamically loaded with file_LoadFunction). Will these result just in a mem_Free failed result or will it mess up my memory?
Regards,
Valentin
#platform "uLCD-32PT_GFX2"
func main()
var t;
gfx_ScreenMode(4);
print("Heap before allocation: ", mem_Heap(),"n"); //prints 13752 (OK)
t:=mem_Alloc(2000);
print("Heap after allocation: ",mem_Heap(),"n"); //prints 11748 (OK)
print("Successful dealocation: ", mem_Free(t),"n"); //prints 2 (OK, should be 1, but it is still TRUE)
print("Heap after deallocation: ",mem_Heap(),"n"); //prints 13752 (OK)
print("Second dealocation: ", mem_Free(t),"n"); //prints 3 (?? should fail?)
print("Heap after second deallocation: ",mem_Heap(),"n"); //prints 13224 (?? where have 528 bytes go?)
print("Deallocating 0 pointer: ",mem_Free(0),"n"); //prints 0 (OK)
print("Heap after 0 deallocation: ",mem_Heap(),"n"); //prints 12312 (?? another 912 bytes missing?)
print("Deallocating -1 pointer: ",mem_Free(-1),"n"); //prints 4 (??)
print("Heap after -1 deallocation: ",mem_Heap(),"n"); //prints 13752 (OK all missing bytes are back?)
repeat forever
endfunc
If I do everything correctly, all the functions work fine, but especially if I do something wrong, the replies are a bit beyond a simple TRUE and FALSE. Can you explain what is the meaning of these return values? Also, if there is a problem, the function is able to detect it and returns 3 instead of 2, but still changes some memory?
Also, what will happen, if I try to deallocate a static function (not dynamically loaded with file_LoadFunction). Will these result just in a mem_Free failed result or will it mess up my memory?
Regards,
Valentin
#platform "uLCD-32PT_GFX2"
func main()
var t;
gfx_ScreenMode(4);
print("Heap before allocation: ", mem_Heap(),"n"); //prints 13752 (OK)
t:=mem_Alloc(2000);
print("Heap after allocation: ",mem_Heap(),"n"); //prints 11748 (OK)
print("Successful dealocation: ", mem_Free(t),"n"); //prints 2 (OK, should be 1, but it is still TRUE)
print("Heap after deallocation: ",mem_Heap(),"n"); //prints 13752 (OK)
print("Second dealocation: ", mem_Free(t),"n"); //prints 3 (?? should fail?)
print("Heap after second deallocation: ",mem_Heap(),"n"); //prints 13224 (?? where have 528 bytes go?)
print("Deallocating 0 pointer: ",mem_Free(0),"n"); //prints 0 (OK)
print("Heap after 0 deallocation: ",mem_Heap(),"n"); //prints 12312 (?? another 912 bytes missing?)
print("Deallocating -1 pointer: ",mem_Free(-1),"n"); //prints 4 (??)
print("Heap after -1 deallocation: ",mem_Heap(),"n"); //prints 13752 (OK all missing bytes are back?)
repeat forever
endfunc
Comment