Hello,
I have an embedded Julia setup where there’s a struct holding vectors of other structs allocated in Julia. The parent struct is stored in a global Ref
and the pointers to data
fields of the parent struct’s vector-typed fields are written to from outside of Julia. It works great for primitive value types but I’ve had some trouble with passing through strings (fixed max size, ASCII-only). Is the solution below the best I can do on Julia 0.6?
struct Value
str :: SVector{10, UInt8}
end
struct Parent
values :: Vector{Value}
end
global const STATE = Ref{Parent}()
function parse_ascii(vec :: A) where {A <: AbstractArray{UInt8, 1}}
res = Vector{UInt8}()
for i in eachindex(vec)
if vec[i] == 0
break
end
push!(res, vec[i])
end
String(res)
end
// called after the memory has been written to
function process()
println(parse_ascii(STATE[].values[1].str))
end
I’m wondering if there’s a way to obtain a stable pointer to the STATE[].values[1].str
and e.g. wrap it into a WeakRefString
- couldn’t find a way to do this.