Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Erroneous malloc() behaviour: (2 Items)
   
Erroneous malloc() behaviour  
Hello!

This is probably a quite indefinite question, but does anyone know of erroneous malloc() behaviour in running QNX 6.3.x 
on MPC8555E targets (compiler version and optimization flags seem to be irrelevant; I tried 2.95.3 and 3.3.5)?

I have the following issue:
When allocating two byte arrays (one directly after the other; size: 256 Bytes), malloc() sometimes returns the same 
pointer address in the 2nd call as it has already returned in the 1st one. Hence, both array pointers actually point to 
the same address.

The actual malloc() calls are located in a sub-function of a self-written shared library, invoked at runtime (.so). The 
erroneous behaviour was detected by adding appropriate printf() calls directly afterwards, outputting the two pointer 
adresses.

Could it have to do something with the shared library usage, or with a too small stack size due to nested sub-function 
calls?

I would appreciate any ideas. I hope, this post does not lack any important information - if so: sorry for that.

Regards,
Markus
Re: Erroneous malloc() behaviour  
Ok, I got it.

It had to do with improper cache line invalidation, causing the malloc-internal memory management to get confused.

Hence, here's some advice for anyone using DMA in combination with caching:
Be aware of the cache line size of your target system and handle it properly!

In my case, the most convenient solution was to disable caching for the DMA buffer area (by allocating it using mmap 
instead of malloc) and using a (cached) shadow buffer for actually processing the data in my application.