tags:

views:

40

answers:

1

Hi,

Is there a POSIX function equivalent to _malloc_r and _free_r from CYGWIN? Is there a POSIX reentrant library?

Please advice.

Many thanks.

+6  A: 

No, and for good reason. Demanding reentrancy of malloc, even if only for special _r functions, would impose massive performance costs and likely precludes many high-performance implementations to begin with. Why do you need reentrancy? If you're trying to allocate memory from a signal handler, you might use mmap, but a better approach would be moving as much code as possible out of the signal handler and using the signal handler itself only to set a flag that will get picked up by another part of your program after the signal handler returns.

R..
Hi thanks, could you possibly suggest more how can I implement reentrancy using malloc and free functions.
sasayins
You can't. These functions are not reentrant, so there is no way to implement reentrant allocation on top of them.
R..
I see, so I must implement another way without calling the malloc and free, like you suggested above.
sasayins