Hi Tim,

Thank you so much for your advice! Finally the problem is solved, and my eyes 
are filled with tears T T. 

Can I really get a pink elephant? Again, thank you!

Yijing
> On Dec 1, 2014, at 9:08 PM, Tim Holy <[email protected]> wrote:
> 
> John is right that if you change to
> 
>    B=fill!(Array(Vector{Int},5,5),Int64[])
> 
> then you don't see the weird allocations. (Note: you probably really want
> 
>    B = Vector{Int}[Int[] for i = 1:5, j = 1:5]
> 
> so each element of B is independent.)
> 
> 
> Still, this one should win some kind of prize for "strangest allocation 
> result 
> of 2014." Where would you like your plastic pink elephant mailed to :-)?
> 
> --Tim
> 
> On Monday, December 01, 2014 06:45:33 PM Yijing Wu wrote:
>> Sorry it seems that I simplified my problem too much in the previous code.
>> Actually I am running something similar to the following, and I run it as a
>> function and it starts to have allocation since i=512. I am really unsure
>> if it's my coding problem(so it can be improved to 0 bytes) or it is
>> natural in the system that allocations appear. Thank you so much!
>> 
>> function test()
>> 
>> B=fill!(cell(5,5),Int64[])
>> 
>> 
>> for i=1:513
>> 
>>        push!(B[2,3],i)
>> 
>> end
>> 
>> 
>> T=zeros(Int64,513)
>> 
>> 
>> for i=1:513
>> 
>>        @time T[i]=B[2,3][i]
>> 
>>        println(T[i])
>> 
>> end
>> 
>> end
>> 
>> 
>> 
>> 在 2014年12月1日星期一UTC-6下午7时24分31秒,John Myles White写道:
>> 
>>> Did you run this inside a function? If not, your results are not going to
>>> be useful indicators of how code will perform inside a function.
>>> 
>>> Inside of a function body, I see 0 bytes being allocated.
>>> 
>>> -- John
>>> 
>>> On Dec 1, 2014, at 4:53 PM, Yijing Wu <[email protected] 
>>> <http://gmail.com/> <javascript:>>
>>> wrote:
>>> 
>>> Hi all, I found a strange problem about a very simple code in julia and
>>> hopefully I can get some help from you, here is the code:
>>> 
>>> 
>>> B=[1:1000]
>>> 
>>> T=zeros(Int64,1000)
>>> 
>>> for i=1:1000
>>> 
>>>        @time T[i]=B[i]
>>> 
>>>        println(T[i])
>>> 
>>> end
>>> 
>>> 
>>> And when I run the code, the @time shows that it require 48 bytes
>>> allocation when i is larger than or equal to 512, and 0 bytes when
>>> smaller. Is this a problem that can be improved or I have to accept that
>>> it is designed to take some allocations when larger than 512?
>>> 
>>> 
>>> Thanks a lot for your help!

Reply via email to