Re: Reentrant functions and memory allocation



fmassei@xxxxxxxxx wrote:

I'm trying to put some old code in a portable, cross-platform
library and I'm facing a big problem: is there a standard,
platform-independent way to write a reentrant function that
allocate dynamic memory? In other words: is it safe to use
malloc() or free() in a thread-safe function?

No. Because the malloc system will be operating on it's own memory
areas, and is not re-entrant. You have to ensure that all accesses
to the malloc package are done through appropriate guards.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: Reentrant functions and memory allocation
    ... mallocor freein a thread-safe function? ... Because the malloc system will be operating on it's own memory ...
    (comp.lang.c)
  • Re: Reentrant functions and memory allocation
    ... mallocor freein a thread-safe function? ... to the malloc package are done through appropriate guards. ...
    (comp.lang.c)
  • Re: When to check the return value of malloc
    ... memory as long as you get it in 20-byte chunks? ... PROVIDED you malloc it in 20 byte chunks. ... You might be perfectly safe to allocate 64K according to ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)
  • Re: structure and malloc
    ... Your solution has 2 calls to malloc. ... I'd have already given the instructor an F for requiring the argument to FreeDEFto be a ABC* and then walked out of the class to go get a refund. ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)
  • Re: A solution for the allocation failures problem
    ... It is not possible to check EVERY malloc result within complex ... Pardon me.I haven't programmed for a few years but I was involved ... Try the download section. ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)