delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/28/11:30:03

Message-ID: <338C4F32.1324@eik.bme.hu>
Date: Wed, 28 May 1997 17:28:50 +0200
From: "Dr. Andras Solyom" <REMOVE_ME_FROM_HERE_solyom AT eik DOT bme DOT hu>
Reply-To: REMOVE_ME_FROM_HERE_solyom AT eik DOT bme DOT hu
Organization: Technical University of Budapest
MIME-Version: 1.0
To: djgpp <djgpp AT delorie DOT com>
Subject: Re: C or C++
References: <5lrt2d$qun AT bambam DOT soi DOT city DOT ac DOT uk> <5mftso$2nc AT butch DOT lmms DOT lmco DOT com> <338C31B9 DOT 3146 AT ll DOT mit DOT edu>

Nathan Gray wrote:
> 
> Since we're on the subject of C and C++, does anyone have a good
> explanation for the differences between malloc() and new?  As a native
> C++ programmer, my first instinct is to use new, but I see malloc() so
> often I'm starting to wonder if I'm missing something.

Well, I am not a big C++ expert, as I usually prefer programming in C,
but this is what I think:
	new calls the constructor of a class while malloc does not.
This means that if a class does not use any other constructor just the
default one, you can allocate memory for an instance of this class using
malloc (or calloc), and free it via free(), while if your class depends
on some constructor code to allocate some memory for it for instance,
then you must use new.

				Andras

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019