LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Are there any problems associated with dynamic memory allocation in a timer callback function?

I'm trying to malloc some memory, do some processing, and then free it within a timer callback and am having problems usually associated with stray pointers.

Memmory corruption appears to be occurring even though I've simplified the malloc and free and no processing is occurring on the memory within the callback, yet after five timer events side-effects occur. (In this case the Random() toolbox function begins to return NaN.)

Are there any inherent problems with dynamic memory use in a timer callback function?

Thanks.
0 Kudos
Message 1 of 3
(3,226 Views)
Do you have any short sample code we could look at ?
Just to let you know. I newer encoutered such issue nor hear about it
before.
--
Regards, Philippe
Feel free to visit : http://perso.wanadoo.fr/philippe.baucour



"SimonRobbins" a écrit dans le message de news:
506500000008000000F6810000-1042324653000@exchange.ni.com...
> I'm trying to malloc some memory, do some processing, and then free it
> within a timer callback and am having problems usually associated with
> stray pointers.
>
> Memmory corruption appears to be occurring even though I've simplified
> the malloc and free and no processing is occurring on the memory
> within the callback, yet after five timer events side-effects occur.
> (In this case the Random() toolbox function begins to return N
aN.)
>
> Are there any inherent problems with dynamic memory use in a timer
> callback function?
>
> Thanks.
0 Kudos
Message 2 of 3
(3,226 Views)
Thanks for your reply.
Unfortunately I've re-written the code, so it's not really applicable for me to post it anymore. What I've done now is to allocate the memory prior to activating the timer, and free it when the timer's deactivated. If the memory size needs to be changed I then set a flag and the memory is reallocated within the timer if the flag's set. This seems to have solved the problem, (though I don't understand why.)

Simon
0 Kudos
Message 3 of 3
(3,226 Views)