Python lists is also basically a continuous array of pointers, the only
reason they appear fast, is that the rest of python is so slow. Copying a
chunk of contiguous memory is actually often faster than traversing a
linked list.
Ivar
kl. 13:08:45 UTC+2 tirsdag 5. august 2014 skrev Neal Becker følgende:
>
> Thanks. I don't think that's really equivalent though. I believe
> python's list
> is not contiguous, and can efficiently handle insertions and deletions,
> both at
> the ends and in the middle. Julia's array is a contiguous dense array,
> correct?
>
> Jason Merrill wrote:
>
> > julia> {}
> > 0-element Array{Any,1}
> >
> > is like python's arrays in that it can hold values of heterogenous
> types,
> > and you can grow it with push!, e.g.
> >
> > julia> a = {}
> > 0-element Array{Any,1}
> >
> > julia> push!(a, "grapes")
> > 1-element Array{Any,1}:
> > "grapes"
> >
> > julia> push!(a, 3)
> > 2-element Array{Any,1}:
> > "grapes"
> > 3
> >
> > If you know the type of all the things you'll be putting in your
> container,
> > you will get better performance/memory efficiency with a typed array.
> >
> > julia> b = Float64[]
> > 0-element Array{Float64,1}
> >
> > julia> push!(b, 1.0)
> > 1-element Array{Float64,1}:
> > 1.0
> >
> > julia> push!(b, NaN)
> > 2-element Array{Float64,1}:
> > 1.0
> > NaN
> >
> > I think in either case, Julia is smart about growing the array by the
> right
> > amount at the right time to get O(1) ammortized push!(), but if you have
> a
> > guess about the eventual size of your array, you can help Julia out with
> > `sizehint`.
> >
> > julia> sizehint(b, 100000)
> >
> > You don't have to be exactly right with sizehint--the worst that will
> > happen is that you will use a little more memory than you needed to, or
> the
> > array will have to be dynamically grown more often than it had to be.
> For
> > this, I am most grateful. In Matlab, your choices are, AFAICT, 1) know
> the
> > exact size of your container correctly ahead of time, 2) have terrible
> > performance, or 3) allocate something that's definitely bigger than you
> > need, and then keep track of how much of it you've used yourself and
> throw
> > away the excess at the end.
> >
> >
> > On Monday, August 4, 2014 4:16:27 PM UTC-7, Neal Becker wrote:
> >>
> >> What would be similar to python list type? A container that has an
> >> efficient
> >> append. A common use is construct an empty list, then grow it by
> calling
> >> append.
> >>
> >>
>
>
>