Resize arrays in mutable structs

There is absolutely no problem with resizing a Vector contained in a struct or mutable struct in Julia. It’s a perfectly normal and common thing to do. The only potential issue is if some other part of your program assumed that the exact memory address of that vector’s data would be constant forever, since resizing a Vector can cause its underlying data to be moved around. This isn’t a problem for purely Julia code, but it could be an issue when interacting with C/FORTRAN.

For example, if you passed that Vector as a Ptr{Float64} to your FORTRAN code, and that code stored that address for later use, then you could end up in a situation where your FORTRAN code was still pointing to the old data address after the resize.

From what I can tell, it doesn’t sound like you’re doing that, so I don’t see any problem.

5 Likes