malloc / free

13 Mar 2012

I'm currently workink on a speedup of my TFT lib. I use the DMA to transfer the pixel to the spi. It work - cls is 6 times faster - but on my final tests I came across a problem :

I use malloc to get a buffer for the pixel data of a char. The font only store bit data which has to be repaced by 16 bit colors. It work for small fonts, but if I use a big font the malloc stop. For 42 * 35 pixel I need 1470 words. It work for some chars, but then the malloc stops. I check all malloc / free and it looks good. If I look on the addresses I get from malloc, I see that I get a different address for the last working char ... There has to be a bug in Mbed malloc / free.

I will try to export the code to the offline compiler to check.

Peter

13 Mar 2012

Peter Drescher wrote:

I'm currently workink on a speedup of my TFT lib. I use the DMA to transfer the pixel to the spi. It work - cls is 6 times faster - but on my final tests I came across a problem :

I use malloc to get a buffer for the pixel data of a char. The font only store bit data which has to be repaced by 16 bit colors. It work for small fonts, but if I use a big font the malloc stop. For 42 * 35 pixel I need 1470 words. It work for some chars, but then the malloc stops. I check all malloc / free and it looks good. If I look on the addresses I get from malloc, I see that I get a different address for the last working char ... There has to be a bug in Mbed malloc / free.

I will try to export the code to the offline compiler to check.

Peter

generally not a good idea to use free() in a small memory microprocessor.

13 Mar 2012

You might want to check out this forum post by Wim. I think the output from a __heapvalid((__heapprt)fprintf,stderr, 1); call just before making the malloc call that fails, could be interesting to diagnose your problem. By the way, when using __heapvalid(), you should have already called something like fprintf(stderr, "Some text\n"); before so that the stderr file descriptor will already have made any dynamic allocations that it might need to make.