This is the mail archive of the gdb@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]

Re: [RFA] alloca coding standard


Jim Blandy wrote:

> > alloca should not be used on with any value that is data dependent,
> > unless it can be shown that the value will never be bigger than your
> > max size for alloca
> 
> It seems to me that if you can establish a maximum size, you might as
> well simply declare the array to be that large to begin with, and
> forget about alloca altogether.  Your constraint sounds like "You may
> only use alloca when it's not needed."  :)

It is the old attage of do it right the first time (in which case
nothing is ever done :-).  It is a case of tradeing off a quick fast
easy solution with a more permenant robust one.  The decision to use
alloca() to resolve multi-arch problems being an example of how
difficult making that that tradeoff can be.

I suspect that there are plenty of things that can still (ab)use alloca
(string routines come to mind).

In terms of documenting this, I'd personally first let the debate settle
down a little (on the internet everything moves very slowly, you can't
decide anything in less than a week :-) and then just clearly document
the objective points that should be considered when using the function.

The two points I'd be taking from this part of the thread are that:

	o	an arbitrary limit of one page
		is just that.  More concrete
		observations such as ``look you've
		got no more than 512k of total
		stack to play with so alloca()ing
		very large chunks of memory very
		early on is likely to blow the stack.

	o	care should be taken when alloc()ing
		data structures based on external
		inputs.

	Andrew

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