OS_Heap 2 / OS_Module 6 differences
Jon Abbott (1421) 2651 posts |
The following invalid claim allocates a 32 byte block (presumably a minimum size):
The equivalent OS_Heap call returns the error “Not enough memory (in heap)”:
So we get two “features” for the price of one. OS_Module should fail the claim as its invalid and OS_Heap should return a more appropriate error. |
nemo (145) 2554 posts |
OS_Heap’s response to a zero-sized allocation has always been silly, especially as it otherwise rounds up allocations to 8n+4 – zero ought to result in a 4 byte allocation really. OS_Module,6 however rounds up the allocation to a size of 16n+12 before calling OS_Heap, which means it’s happy to do an allocation as small as -3. As neither of these routines return the size they have actually allocated and there’s no call to read the size of an OS_Module block, one has always had to rely on two assumptions: • OS_Module uses OS_Heap and exclusively uses DynamicArea 1 for allocations Also note that because of this undocumented rounding up, OS_Heap,4/OS_Module,13 behave very strangely: If they are used to shrink a block enough, then the block will be freed (and a pointer of -1 returned). However, enough is rather difficult to predict. I invite the reader to experiment and express surprise. |