snq
Experienced Member
I'm working on a program/lib that sometimes needs to allocate more memory while in an interrupt handler. I guess this is generally frowned upon but I like the idea better than hogging memory in advance, not knowing if we actually need it or not. I'm using the regular malloc()/_fmalloc() (using compact memory model so far pointers) to allocate memory and it all works fine until the current heap is full. What happens then is it can't allocate any more memory and everything goes mad.
My workaround that seems to work is to allocate all available memory at startup and then immediately free it again, to force the crt to create the heaps in advance.
So that works but it's not exactly ideal. All memory is still available to my app so no problem there. But I can probably forget about using exec..()/system() etc and I may actually need to use those functions at some point. I'm sure there's a way to free up the heaps again but that'd just result in everything going mad again.
Is there a proper solution for this or should I just the reserve memory in advance?
My workaround that seems to work is to allocate all available memory at startup and then immediately free it again, to force the crt to create the heaps in advance.
So that works but it's not exactly ideal. All memory is still available to my app so no problem there. But I can probably forget about using exec..()/system() etc and I may actually need to use those functions at some point. I'm sure there's a way to free up the heaps again but that'd just result in everything going mad again.
Is there a proper solution for this or should I just the reserve memory in advance?