Memory{T} in 1.11


While running my code with the 1.11 alpha 2 version of Julia, it broke due (I think) to a change introduced in Julia 1.11.

In the following code:

d = IOBuffer("hello")
dd =

dd is a Vector{UInt8} in julia 1.10 but is a Memory{UInt8} in 1.11.
Which broke my code because there is no insert! function for Memory{UInt8}

1/ the Julia documentation says it is “One-dimensional dense array with element of type T.” What is the difference with Vector{T} ? And in which case should I use Memory?

2/ is there an easy way to convert Memory to Vector?

3/ is there a plan to add an insert function for Memory?

Thank you

In general, the fields of objects in Julia are considered internal. So, there is no guarantee that fields of objects don’t change in minor versions. I’ll admit it’s not at all clear to users of Julia what is and isn’t internal, though. To prevent issues like this in the future, I recommend structuring your code so you don’t need to access individual fields of types that are not your own. Anyway, to your questions:

  1. Memory is more low-level, as it doesn’t support multiple axes (dimensions), and it can’t dynamically change size. You can think of a Vector as a Memory plus to integers - an offset and a length. If you know that you don’t need to resize a vector, Memory removes a small amount of overhead

  2. collect(mem) to create a new Array copying the elements, and wrap to create a new array backed by the memory.

  3. That’s not possible, because the whole idea of Memory is to be lower level, which is possibly precisely because it can’t change size. So that can’t be done.