On Saturday, May 17, 2014 02:04:49 PM Andrew Dabrowski wrote:
> But is it wrong to use it the way I suggested?

Not wrong, but whether it buys you anything depends on what comes next. The 
sizehint takes effect after the call to f(oldarray) returns, and it doesn't 
affect f at all. However, if the next thing you do with newarray is to grow it, 
then the sizehint might be useful.

Best,
--Tim


> On Saturday, May 17, 2014 4:27:19 PM UTC-4, Tim Holy wrote:
> > I use it right after creating an array that I'm going to be modifying with
> > push!:
> > 
> > a = Array(Int, 0)
> > sizehint(a, 10^5)
> > 
> > Now I'll be able to push! at least 10^5 elements without it having to re-
> > allocate and copy the data I've already added.
> > 
> > --Tim
> > 
> > On Saturday, May 17, 2014 09:29:49 AM Andrew Dabrowski wrote:
> > > What's the proper way to use sizehint when defining a new array?  Is it
> > > 
> > > newarray = sizehint( f( oldarray ), n ),
> > > 
> > > or do you have to already have the new variable defined before using
> > > sizehint?

Reply via email to