This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use of malloc() in v3


On Tue, Nov 11, 2003 at 06:10:55PM +0100, Paolo Carlini wrote:
> Stephen M. Webb wrote:
> 
> >I've been stumbling across several places in libstdc++ where malloc() is 
> >used instead of ::operator new().  Since I'm working on a platform that 
> >doesn't supply malloc(), this inconveniences me.
> >
> I see. I'm not going into the technical details (first blush I agree that
> replacing malloc with new is a good idea), only want to point out that 
> basically
> we have malloc only in a couple of places for the generic locale model 
> (not for
> the gnu locale model), in the malloc allocator ;), and in _Temporary_buffer,
> __get_temporary_buffer and libsupc++.
> 
> The latter are the oldest and puzzle me most. Why malloc?

The main reason for me to use malloc instead of new
is when I need realloc.  Otherwise the only reason is
that it does a call less (normally 'new' just calls malloc());
considering how slow malloc() is, that shouldn't be a reason
when there is any other reason why using new is prefered.

The conclusion is that if the allocated pointer is not
passed to user space (allowing the user to free or realloc it),
and when we don't use realloc ourselfs, then you can replace
malloc(size)/free(ptr) with new char [size] / delete [] ptr,
without problems.

-- 
Carlo Wood <carlo@alinoe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]