help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %union errors that shouldn't be there


From: Hans Aberg
Subject: Re: %union errors that shouldn't be there
Date: Sun, 27 Mar 2005 21:07:38 +0200

At 17:50 +0100 2005/03/26, Laurence Finston wrote:
 > With unions, one wants to avoid dynamic allocations. Each dynamic
 allocation takes several tens, sometimes, hundreds of cycles.

If pointers are used, then memory needs to be allocated for the objects they
point to, whether the pointers are in a `struct' or a `union'.  It needn't be
allocated dynamically in either case.

I don't see any advantage to having multiple
members of pointer types in a `union', e.g.,

I guess the cleanup is generally different. But use whatever you feel comfortable with.

 > Unions are faster than dynamic allocations, and in the past, it was
 important that they take little space.

I have nothing against `unions'.  I think if pointers are going to be used
anyway, then a single `void*' could be used for all types, in which case there
would be no need for a `union'.   If class types are to be allowed, the
constructors of objects of these types might be performing dynamic allocation,
so it might not pay to take the trouble of avoiding it for the other types.  I
think it's an interesting problem.

The idea with extended unions, avoiding pointers, would be to avoid having to do hand code special cleanup.
--
  Hans Aberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]