Can anyone comment on the underlying memory allocation behavior of these 
two operations?  I believe push! will potentially allocate more memory than 
needed for the resulting array in the case that any new memory needed to be 
allocated?  Does it double the size of the underlying allocated memory? 
 Will append! do something similar?

Most importantly, is there an easy way to find this information?  E.g., is 
there a direct way I can find out how much memory (maybe in units of 
elements) is allocated under an array?

I need to grow some arrays (conceptually by appending data from one to 
another), and this is going to happen a lot such that it would be very bad 
if the first array was copied for every single append.

Thanks.

On Wednesday, August 7, 2013 at 2:49:09 PM UTC-4, Randy Zwitch wrote:
>
> Reading through documentation, it isn't really clear to me what the 
> difference between push! and append! is. Meaning, coming from a Python 
> background, I would've expected the behavior of push! to be named append!, 
> as in Python:
>
> Python:
>
> In [3]: nums = [1,1]
>
> In [4]: nums.append(2)
>
> In [5]: nums
> Out[5]: [1, 1, 2]
>
>
> Julia
>
> julia> nums = [1,1]
> 2-element Int64 Array:
>  1
>  1
>
> julia> append!(nums, 2)
> ERROR: no method append!(Array{Int64,1},Int64)
>
> julia> push!(nums, 2)
> 3-element Int64 Array:
>  1
>  1
>  2
>
>  What am I appending when I use append! and not push!, another object?
>

Reply via email to