5

Suppose I write this function

    function test_function(T)
        c = 1
        d = 31
        q = 321
        b = 32121
        a = 10
        for i in 1:T
            c = d + q + b + a
        end
    end

There will be no memory allocation. However, in my own code, I wrote a similar loop, but I encounter a huge amount of memory allocation. I can't share the entirety of my code, but when I used --track-allocation=user, I see the following results

    80000     q      = 3
        -     p      = 0.1
        -     p_2    = 3
        -     q_2    = .2
        -
   240000     r      =  p - p_2 + q_2 - q;

The code above is in a for loop. This is just strange to me - why would Julia ever allocate memory to single digits?

user1691278
  • 1,751
  • 1
  • 15
  • 20

0 Answers0