Hello everybody,
I'm comparably new to Julia, but not completely new to programming. Yet,
I'm a biologist by training, so please excuse potentially dumb questions in
advance :)
I am working in evolutionary ecology, programming individual-based
simulations. I have now transferred a (very) simple program that simulates
insect populations into Julia and am so far happy with its performance and
style (I really fell in love with Julia). Yet, I do have a performance
problem when it comes to copying a complex object. First of all my basic
type structure:
type TInd # an individual
ld::Float64
disp::Bool
end
type TPop # a single population
ind::Array{TInd,1}
end
world = TPop[] # just to mention, this is NOT a global variable, but in my
main simulation function to create multiple populations
You see that I have a set (world) of populations (TPop), each being defined
as arrays of individuals. During reproduction, I create a second Array of
individuals, that stores the (mutating) offspring. So far so good. Yet,
since I assume discrete generations, after each individual in a population
has reproduced, the parental population is to be replaced by the offspring.
I have implemented that like this:
newpop = TInd[]
# ... then the new population gets filled with offspring ...
world[p].ind = deepcopy(newpop)
Of course, this solution is working, but it is really slow. And since I do
actually not need a copy of the newpop, but just want it to overwrite the
original population, I guessed there might probably be a faster and more
elegant solution (without complex workarounds, just somehow adjusting the
pointers!?)? From what I've seen the model will probably run faster than in
C++ as soon as I find the answer :)))
I appreciate any help, thanks a lot in advance!
All the best,
Alex