How to efficiently transform vector of structures without unnecessary allocation? We have two structures:
struct ApiData
name::String
reload::Vector{ApiReload}
values::Vector{Float64}
end
struct ApiReload
status::String
time::Sting #Transform to sturcture "TimeOfDay"
end
which make the vector a = Vector{ApiData}. Now we want to transform the vector a into vector b which has the form of three structures:
struct Data
name::String
reload::Vector{Reload}
values::Vector{Float64}
end
struct Reload
status::String
time::TimeOfDay
end
struct TimeOfDay
minutes::Array{Int}
hours::Array{Int}
end
Vector b has the form of Vector{Data}, with percentage members in the Data structure (name =1%, reload=4% and values 95%).
You haven’t specified how fields should be transformed, so I’m just guessing on the similarity of type names, but then its not clear how ApiReload with a single String should map to Reload having Array{Int} for minutes and hours.
Now, looking at your last line:
Vector{Data} , with percentage members in the Data structure…
should the transform contain any calculations as well, or is it merely a structural transformation?
If you want less allocations and more speed you can replace the broadcasting by manual preallocation of the vectors and explicit loops.
It would be easier for others to help if you present your current solution and describe what you’d like to improve. (nota bene: I’m still learning Julia, so I might have missed something, but till now I’ve never come across a generic structural transformation design pattern).