This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [top-level] C++-friendly allocators for libiberty



> 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 guess daniel had this in mind:


/* Utility macros to allocate typed memory.  Avoids errors like:
   struct foo *foo = xmalloc (sizeof struct bar); and memset (foo,
   sizeof (struct foo), 0).  */
#define XZALLOC(TYPE) ((TYPE*) memset (xmalloc (sizeof (TYPE)), 0, sizeof (TYPE)
))
#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
#define XCALLOC(NMEMB, TYPE) ((TYPE*) xcalloc ((NMEMB), sizeof (TYPE)))

They first appeared in GDB in '99 and were added to GDB's global header file in '02 (and I'm sure the idea was stolen from elsewhere). Unlike the macros being proposed, these:


- use uppercase to make it very very clear that they are macros
- are named in a way that directly reflects their C herritage

While I agree with the type casing idea underlying "xnew" et.al. (I was in part responsible for the above :-), I don't see any benefit in adopting C++ names and pretending that we're writing C++.

Andrew



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]