Message-ID: <338C4F32.1324@eik.bme.hu> Date: Wed, 28 May 1997 17:28:50 +0200 From: "Dr. Andras Solyom" Reply-To: REMOVE_ME_FROM_HERE_solyom AT eik DOT bme DOT hu Organization: Technical University of Budapest MIME-Version: 1.0 To: djgpp 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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