This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [top-level] C++-friendly allocators for libiberty
Daniel Jacobowitz wrote:
> On Sat, Jun 26, 2004 at 04:39:04AM +0200, Bernardo Innocenti wrote:
>
>>Ian Lance Taylor wrote:
>>
>>>Bernardo Innocenti <bernie@develer.com> writes:
>>>
>>>
>>>
>>>>On second thought, the interface for xrenew() or xresize() wasn't
>>>>even usable without a size argument.
>>>
>>>Oh yeah.
>>>
>>>
>>>
>>>>Maybe this would be better?
>>>>
>>>> #define xrenewvec(P, T, N) (T *) xrealloc ((P), sizeof(T) * (N))
>>>
>>>
>>>No, people use realloc with variable size arrays at the end of
>>>structs. xrenewvec (or xresizevec) is a good idea, but you still need
>>>xrenew (or xresize).
>
>
> Bernando, you've now got an interface which allows reallocating to a
> variable size, but not allocating to one... There's no need for a
> rush, let's give people some time to comment before putting this into
> libiberty. As DJ says, it's hard to take things out of libiberty.
I've not yet committed anything, but I see your point.
There's good symmetry here:
struct foo *v = xnewvec (struct foo, 42);
v = xresizevec (struct foo, v, 666);
xdeletevec (v);
But not here:
struct varsize *s = ???
s = xresize (struct varsize, s, sizeof (struct varsize) + strlen (name));
xdelete (s);
Maybe we should add this:
#define xvarnew(T, S) (T *) xmalloc (S)
Another possibility would be dropping this realloc interface
altogether and sticking with a simpler interface that has
the same limitations of C++.
--
// Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/ http://www.develer.com/