General discussions about working with the Astrobe IDE and programming ARM Cortex-M3, M4 and M7 microcontrollers.
2 posts • Page 1 of 1
it took me a long time to fix a nasty problem that looked like memory being overwritten somehow. I found out that the overwritten memory -a record allocated on heap- was allocated during the MODULE Initialisation sequence before the body of MODULE Storage got called which reset the heap start address to its initial value. The result was that subsequent calls to NEW allocated same heap area already used by blocks allocated before initialisation of MODULE Storage! The cure was easy, moving 'Storage' in the IMPORT list helped. For the moment I import 'Storage' in MODULE 'Main'. Is this a foolproof scheme or do you recommend another solution?
Storage is a special case and you do have to be careful in its use - I'll make a note to point this out in the documentation. Note that you only need to import Storage if you have modified it in any way. The compiler automatically imports MAU and calls its functions when you use NEW and DISPOSE. If you have modified Storage then you should call it before you make any calls to NEW / DISPOSE. If I understand you correctly, I think it should work OK if you call Storage.Allocate in the same MODULE initialisation sequence where you make the first call to NEW.