lancaster-university / microbit-dal

http://lancaster-university.github.io/microbit-docs
Other
254 stars 130 forks source link

MicroBitHeapAllocator: how does the calculation work? #357

Open gruenwaldi opened 6 years ago

gruenwaldi commented 6 years ago

I was working on a bigger code example for the microbit, when i stumbled over the MicroBitHeapAllocator. At first it seem to be a good tool, but I do not understand the calculation in relation to startup_NRF51822.S, where the original heap and stack regions are defined. Also it seems that the HeapAllocator assumes that heap + stack = 4672 Bytes, however the NRF51822.ld only allows 4096 Bytes. Additionally the nested heap does not start at RAM_END - 4096 Bytes, but 0xF0 Bytes later, which further reduce the size. So the current configuration overlaps heap and stack which leads to crashes of the NRF51, if the nested_heap_factor remains at 0.75.

finneyj commented 6 years ago

Thanks @gruenwaldi

The heap allocation in NRF51822.S is a little confusing, and the nested heap allocator did add some confusion. We've now moved to running the micro:bit heap allocator instead of the GCC/libc allocator, and simplified the policy here somewhat.

As of version 2.1.0, there will now be a single heap section between the end of statically assigned variables (globals) and the end of a 2K stack region, with no overlap of heap and stack regions. Hope this helps to explain things!

p.s. Apologies for slow response to your issue - wish i had more time available for micro:bit...