Hello community!
I’m running a simulation which requires millions of iterations, and the memory consumption (even temporary) is huge and I would like to reduce it. Pursuing this, I found something that I wasn’t expecting.
I have my own struct defined, with some basic attributes and I noticed using @time
that every time that I want to access a Float64 (or any Float) property it allocates 16bytes
but if the property is an Int, it doesn’t.
Here is my type definition
abstract type AbstractVoltmeter end
struct EChTVoltmeter <: AbstractVoltmeter
EChTVoltmeter() = new()
end
mutable struct ECTVoltmeter <: AbstractVoltmeter
pulse_acum::Float64
phase::UInt8
I::Float64 # Current
ECTVoltmeter() = new(0.0, 1, 1.0)
end
And here is the output
julia> z = ECTVoltmeter()
ECTVoltmeter(0.0, 0x01, 1.0)
julia> @time z.phase
0.000004 seconds
0x01
julia> @time z.I
0.000005 seconds (1 allocation: 16 bytes)
1.0
I know this won’t change much on my memory-leak problem, but I want to understand what is happening.
I notice something similar using Tuples, which always allocates memory when you access one element (not expected by me at all)
Thank you!