# Best way to read a string from a struct field written to through shared memory

**URL:** <https://discourse.julialang.org/t/best-way-to-read-a-string-from-a-struct-field-written-to-through-shared-memory/17516>\
**Category:** General Usage\
**Tags:** embedding, strings\
**Created:** [November 14, 2018, 1:26pm UTC](https://discourse.julialang.org/t/best-way-to-read-a-string-from-a-struct-field-written-to-through-shared-memory/17516 "2018-11-14T13:26:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dm3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dm3/32/2755_2.png) [@dm3](https://discourse.julialang.org/u/dm3)\
**Post date:** [November 14, 2018, 1:26pm UTC](https://discourse.julialang.org/t/best-way-to-read-a-string-from-a-struct-field-written-to-through-shared-memory/17516/1 "2018-11-14T13:26:30Z")

</div>

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?

```julia
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.
