# Understanding meanings of memory allocation numbers

**URL:** <https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871>\
**Category:** New to Julia\
**Tags:** performance, memory-allocation\
**Created:** [June 21, 2018, 8:56pm UTC](https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871 "2018-06-21T20:56:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alirezamecheng](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@alirezamecheng](https://discourse.julialang.org/u/alirezamecheng)\
**Post date:** [June 21, 2018, 8:56pm UTC](https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871/1 "2018-06-21T20:56:58Z")

</div>

Hello,  
I`m a mechanical engineer who is not familiar with pro programming skills. I wrote a CFD code and cheque the performance i.e runtime and memory with `@time` and  
` julia --track-allocation=user --inline=yes`.  
The result is something like this.

`20.860648 seconds (71.33 M allocations: 1.075 GiB, 2.11% gc time)`

```julia
        - # Fluid variables (density and velocity)
        - function Den_vel!(rho::Array{Float64},ux::Array{Float64},uy::Array{Float64},f::Array{Float64})
        0 for c = 1:Nx1
        0 for r = 1:Ny1
1135680000 rho[r,c]=f[r,c,9]+f[r,c,1]+f[r,c,2]+f[r,c,3]+f[r,c,4]+f[r,c,5]+f[r,c,6]+f[r,c,7]+f[r,c,8];
        0 ux[r,c]=(f[r,c,1]+f[r,c,5]+f[r,c,8]-f[r,c,3]-f[r,c,6]-f[r,c,7])/rho[r,c];
        0 uy[r,c]=(f[r,c,5]+f[r,c,6]+f[r,c,2]-f[r,c,7]-f[r,c,8]-f[r,c,4])/rho[r,c];
        - end # for r
        - end # for c
   480000 return rho , ux , uy;
        - end # of function [Den_vel!]

        - const Nx1 = 25;
        - const Ny1 = 25;
        - const Q = 9;

        - function main()
        - # allocations
    48784 f = Array{Float64}(Ny1,Nx1,Q); 
    48784 f_post = Array{Float64}(Ny1,Nx1,Q);
        - 
     5568 rho = Array{Float64}(Ny1,Nx1);   
     5568 ux = Array{Float64}(Ny1,Nx1);
     5568 uy = Array{Float64}(Ny1,Nx1);
        -
        - # doing some stuff ....
        -
        0 while condition 
        -
        - # doing some stuff
        0 rho, ux, uy = Den_vel!(rho,ux,uy,f);
        - # doing some stuff
        -
        - end # of while loop
        - end # of function main

@time main()

```

The while loop iterated `15000` times.  
Please look at this result, I wonder if it is normal or not?  
Note that `rho`, `ux` and `uy` definitions are similar. all of them are allocated in the `main` function and given to `Den_vel!` function as the argument. but `rho` has a lot of allocations and `ux` and `uy` have zero allocations.  
Amount of allocation and gc time is not clear for me.  
What does allocation mean? Does it means that every time the code redefined a place in ram for this variable? or not?  
why `rho` has allocations?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [June 21, 2018, 9:11pm UTC](https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871/2 "2018-06-21T21:11:53Z")

</div>

Try splitting the sum up in a smaller number of terms. At least there has been an issue with this.

```julia
rho[r,c]=(f[r,c,9]+f[r,c,1]+f[r,c,2]+f[r,c,3]+f[r,c,4]) + (f[r,c,5]+f[r,c,6]+f[r,c,7]+f[r,c,8])

```

---

<div class="post-metadata">

**Author:** ![alirezamecheng](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@alirezamecheng](https://discourse.julialang.org/u/alirezamecheng)\
**Post date:** [June 22, 2018, 9:40am UTC](https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871/3 "2018-06-22T09:40:28Z")

</div>

That was interesting for me. It worked. 😯 Why is that happening?🤔  
do you have any idea about the `return` allocation?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [June 22, 2018, 10:05am UTC](https://discourse.julialang.org/t/understanding-meanings-of-memory-allocation-numbers/11871/4 "2018-06-22T10:05:36Z")

</div>

I believe it is related to limitations in how big tuples inference can handle but my search karma isn’t good enough to find the relevant issue number. I’m not sure whether it has been solved in Julia 0.7 but at least those kinds of limits are much higher now, so you are less likely to run into them in the future. Hopefully someone with more insight can comment on that.

Not sure about the return allocation but you have already updated those arrays in place, so there’s no need to return them at all.
