Hi, I have to following types,
typealias ElementSize
typealias Element Array{Float64, 3}
type ElementBuffer
size::ElementSize
alloc::ElementSize
data::Element
end
The following function is called many times,
function set_size!(bf::ElementBuffer, sz::ElementSize, load_old_data::Bool
= true)
if (bf.alloc[1] < sz[1]) || (bf.alloc[2] < sz[2]) || (bf.alloc[3] < sz[3])
old_data = bf.data
bf.alloc = map(max, bf.alloc, sz)
bf.data = Element(bf.alloc)
if load_old_data
load_body!(bf, old_data)
end
end
bf.size = sz
nothing
end
I've seen there is a lot of memory allocation going on, so I've benchmarked
the former code using Julia's track-allocation=user option. The result was
suprising,
- function set_size!(bf::ElementBuffer, sz::ElementSize,
load_old_data::Bool = true)
1710097664 if (bf.alloc[1] < sz[1]) || (bf.alloc[2] < sz[2]) ||
(bf.alloc[3] < sz[3])
0 old_data = bf.data
2894592 bf.alloc = map(max, bf.alloc, sz)
59783056 bf.data = Element(bf.alloc)
0 if load_old_data
0 load_body!(bf, old_data)
- end
- end
0 bf.size = sz
0 nothing
- end
After running the code in debug, I've seen that there is an allocation
happening every time the alloc field is accessed. If I change the field
type from a tuple to an array this phenomenon disappears. I can't figure
out why this allocation is happening, any ideas?
Uri