By "unexpected memory usage", it really means a line that shouldn't be
allocating that nevertheless does. In your case, line 56 is explicitly
allocating (it's creating a new Person object). You could check by using
sizeof(Person) and seeing if the size is correct (but you'd have to include
the size of the Dict, which because a Dict stores arrays is a bit recursive).
Likewise, your push! command will grow the array, and hence allocate memory.
That's being attributed to the first line of the for loop (the reasons are a
little complex, and I'm late for a meeting).
--Tim
On Thursday, November 13, 2014 04:01:52 PM Test This wrote:
> On performance tips page of the Julia documentation, it says that one way
> to identify performance problems is to look for unexpected memory usage.
>
> As suggested, I ran the code with --track-allocation=user option.
>
> The following are some lines from my code (including the type definitions
> at the beginning). For now, I have two questions:
>
> (1) How do I know what is appropriate/expected memory usage? That is, how
> do I calculated expected appropriate usage? A related question is, is the
> usage on line 56 appropriate.
>
> (2) What determines the memory usage for a for-loop? Is the usage on Line
> 66 appropriate?
>
> Thank you.
>
>
>
> - ##
> -------------------------------------------------------------------
> - ## Custom types and constants
> - ##
> -------------------------------------------------------------------
> -
> - type Params
> - minUtil::Int
> - maxUtil::Int
> - numPeople::Int
> - w::Int # inversely related to the weight on reviews
> - pReview::Float64
> - numReps::Int
> - recEveryX::Int
> - end
> -
> -
> - type Good
> - name::ASCIIString
> - mu::Int
> - sigma::Int
> - end
> -
> -
> -
> - type Person
> - id::Int
> - priors::Dict{ASCIIString, Float64}
> - choice::Good
> - util::Float64
> - review::Bool #whether reviews or not
> - stars::Int #if review=true then how many stars
> - end
> -
> -
> -
> - ##
>
===================================================================
> - ## Functions
> - ##
>
===================================================================
> -
> - # Function to initialize a person
> - function createPerson(params::Params,
> - id::Int,
> - xUtilDist::Dist.Uniform,
> - goods::Dict{ASCIIString, Good})
> - # draw xH value
> 0 xHutil::Float64 = rand(xUtilDist)
> * 1728000 p = Person(id, ["H" => xHutil, "L" => 100 - xHutil],
> goods["N"], 0.0, false, 0) # LINE 56*
> - end
> -
> -
> - # create population of persons with there initial xH and xL
> - function createPopulation(params::Params,
> goods::Dict{ASCIIString, Good})
> 288 popn::Array{Person, 1} = []
> - #create a uniform distn with support [0, 100]
> 0 unif = Dist.Uniform(params.minUtil, params.maxUtil)
> -
> * 51456 for i = 1:params.numPeople # LINE 66*
> 0 p::Person = createPerson(params, i, unif, goods)
> 0 push!(popn, p)
> - end
> -
> 0 return popn
> - end