You can also have const bindings to global mutable state without any
performance impact. Passing around a state object is probably better style
though.

On Thu, Sep 15, 2016 at 2:35 PM, Mauro <mauro...@runbox.com> wrote:

> The first style is fine as objects are passed by reference, i.e. there
> are not copies made.
>
> On Thu, 2016-09-15 at 20:15, Nathan Smith wrote:
> > Hi
> >
> > I'm looking for some advice for some on writing methods on large
> (memory-wise)
> > data types. Is there an overhead difference in the following two methods?
> >
> > type State
> >  hugearray1::Array{Float64, 2}
> >  hugearray2::Array{Float64, 2}
> >  ... # Many more components
> > end
> >
> > function style1!(s::State)
> >   complicated_function(s.hugearray1)
> > end
> >
> > function style2!(arr::Array{Float64, 2})
> >   complicated_function(arr)
> > end
> >
> > # difference in calls:
> >
> > s = State(arr1, arr2, ...)
> > style1!(s)          # Pretty but is it slower?
> > style2!(s.hugearray1)    # Ugly but is it faster?
> >
> >
> > Basically, is there an overhead in throwing the whole state datatype
> into a
> > function even if i only manipulate one or two of the potentially large
> amount
> > of components or should I be making functions in the second style where
> > arguments are exactly of the type of the components being manipulated.
> >
> > Thanks!
> > Nathan
> >
> > ps: sorry for the double post, I hit enter before I finished writing..
>

Reply via email to