[Scummvm-devel] CVS: "added extra flag to mixer so we don't use free() on new'd pointers"

David Eriksson david at scummvm.org
Sun Oct 26 04:05:14 CET 2003

Quoting Max Horn <max at quendi.de>:

> Am Samstag, 25.10.03 um 01:42 Uhr schrieb Joost Peters:
> >>> Update of /cvsroot/scummvm/scummvm/sound
> >>> In directory sc8-pr-cvs1:/tmp/cvs-serv26508/sound
> >>>
> >>> Modified Files:
> >>> mixer.cpp mixer.h
> >>> Log Message:
> >>> added extra flag to mixer so we don't use free() on new'd pointers
> >>>
> >> Hrm, is that really necessary? Why can't we just always use free() to
> >> allocate memory for buffers passed to the mixer?
> Sorry, I meant of course: "Why can't we just always use malloc() to 
> allocate memory..."
> >
> So no, I am most definitely not suggesting that you free() memory 
> allocated via new. But rather, I wonder why you have to allocate a 
> buffer with new - it should be trivial to just use malloc() instead...

It is very backwards to oppose the use of C++ in a C++ program.

Joost made a very simple solution to a big problem in ScummVM. Using malloc/free
in a C++ program is just plain wrong, unless your development language actually
is "C with classes" instead of C++.

The way of perfection would be to change all uses of malloc/free in ScummVM to
new/delete, but instead Joost made a simple fix to make the ScummVM sound system
work correctly with a part of ScummVM that actually uses new/delete and not any
C compatibility functions for memory handling.

As suggested in another mail on this thread, a callback function (or a functor)
to destroy the allocated memory would be a more generic solution to the problem
Joost solved without disturbing any other part of ScummVM.


More information about the Scummvm-devel mailing list