Hi Yijing,

Thanks for the update. I'm a little confused by somethings happening in your 
code.

(1) Do you really need to use cell(5, 5)? In general, you'll want to use more 
tightly typed arrays.

(2) Do you really want to fill the B array with many copies of the exact same 
pointer? This seems improbable. Did you perhaps want to create a new Int64[] 
array for every element of B?

 -- John

On Dec 1, 2014, at 6:45 PM, Yijing Wu <[email protected]> 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]> 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