[gccsdk] C++ and malloc

Peter Naulls peter at chocky.org
Mon May 19 13:26:12 PDT 2008


Jan-Jaap van der Geer wrote:
> John Tytgat <John.Tytgat at aaug.net> wrote:
> 
>> In message <3fce88a14f.Jan-Jaap at iyonix.c2i.net>
>>           Jan-Jaap van der Geer <janjaap at dsv.nl> wrote:
> 
>>> I am trying to find an irritating heisenbug in my code.
>>> Sometimes my C++ program exits with malloc errors. The strange
>>> thing is that I do not use malloc in my code, except for one
>>> place, where I do use it. However, when it fails it should not
>>> be anywhere near that code.
> 
>>> So I wonder if C++ / GCC internally use malloc to implement "new"
>>> and stuff like that. Does anyone know?
> 
>> Yes, that's certainly the case. E.g. for the GCCSDK 3.4.6 code
>> base:
>> <URL:http://www.riscos.info/websvn/filedetails.php?repname=gccsdk&path=%2Fbranches%2Frelease_3_4_6%2Fgcc%2Fgcc%2Flibstdc%2Flibsupc%2Fnew_op.cc&rev=0&sc=0>
>> & other flavors of 'operator new'.
> 
> Thanks. Good to know.

Strictly speaking, libstdc++ makes use of malloc for 'new'.  This is
almost always true in C++, except in some very unusual setups - GCC
itself doesn't know much about it except for syntax reasons.  libstdc++
might also use malloc internally, although I suspect not.  UnixLib
also uses malloc internally for various uses - mostly for some
initialisation purposes, but also for some filename conversion
stuff.





More information about the gcc mailing list