Topic: delete and multiple inheritance break malloc?
Author: kanze@us-es.sel.de (James Kanze)
Date: 18 Apr 1994 18:09:31 GMT Raw View
In article <1994Apr11.184414.597@lia.com> daniel@lia.com (Daniel
Edelson) writes:
|> In message <KANZE.94Apr7142530@slsvhdt.us-es.sel.de>, James Kanze writes:
|> } As far as I can remember, none of the ISO C string libraries (declared
|> } in string.h) return a pointer to heap memory. So generally speaking,
|> } you can only delete/free them if *you* allocated them. In this case,
|> } use delete if you allocated them with new, free if you allocated them
|> } with malloc (and neither if they aren't on the heap.)
|> strdup().
|> Strdup() is anathema to C++ programs. It's a core dump waiting to
|> happen. I try to migrate C++ programmers in my group away from
|> malloc/free, and consequently away from strdup().
Strdup is *not* a standard library function, as defined by the ISO C
standard. I have worked on numerous systems where it is not
available. If you are concerned about portability, you shouldn't be
using it anyway. (On the other hand, in C, it is so easy to roll your
own if you happen to hit a machine where it is not implemented.)
In theory, it should not be declared if compiling in strict
compatibility mode. (In practice, I wish this were the worst problem
we had to worry about.)
In C++, of course, the answer is to use string (or String, or
BC_TVariableString, or RWString, or whatever), and forget about the
memory management problem completely.
--
James Kanze email: kanze@lts.sel.alcatel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: daniel@lia.com (Daniel Edelson)
Date: Mon, 11 Apr 1994 18:44:14 GMT Raw View
In message <KANZE.94Apr7142530@slsvhdt.us-es.sel.de>, James Kanze writes:
} As far as I can remember, none of the ISO C string libraries (declared
} in string.h) return a pointer to heap memory. So generally speaking,
} you can only delete/free them if *you* allocated them. In this case,
} use delete if you allocated them with new, free if you allocated them
} with malloc (and neither if they aren't on the heap.)
strdup().
Strdup() is anathema to C++ programs. It's a core dump waiting to
happen. I try to migrate C++ programmers in my group away from
malloc/free, and consequently away from strdup().
Daniel Edelson
daniel@lia.com
Author: rich@kastle.com (Richard Krehbiel)
Date: Tue, 12 Apr 1994 18:11:21 GMT Raw View
In article <1994Apr11.184414.597@lia.com> daniel@lia.com (Daniel Edelson) writes:
> In message <KANZE.94Apr7142530@slsvhdt.us-es.sel.de>, James Kanze writes:
>
> } As far as I can remember, none of the ISO C string libraries (declared
> } in string.h) return a pointer to heap memory.
>
> strdup().
strdup() is (by my reading) not in the ISO standard.
--
Richard Krehbiel rich@kastle.com or richk@netcom.com
Nothing witty comes to mind...