Thank you for those links, they are a great help. Is there an "unprotect_from_gc(T* val)"?
I am looking for a smart pointer a bit like v8's UniquePersistent<>. I guess I could make one that searched through the array for the value in order to remove it (in the smart pointer's dtor). Thanks, Kit On Wednesday, August 10, 2016 at 8:10:34 PM UTC+12, Bart Janssens wrote: > > > > On Wed, Aug 10, 2016 at 9:11 AM Yichao Yu <yyc...@gmail.com <javascript:>> > wrote: > >> On Wed, Aug 10, 2016 at 2:17 PM, Kit Adams <kit....@gmail.com >> <javascript:>> wrote: >> >>> I am investigating the feasibility of embedding Julia in a C++ real-time >>> signal processing framework, using Julia-0.4.6 (BTW, the performance is >>> looking amazing). >>> >>> However, for this usage I need to retain Julia state variables across >>> c++ function calls, so the stack based JL_GC_PUSH() and JL_GC_POP() are not >>> sufficient. >>> When I injected some jl_gc_collect() calls for testing purposes, to >>> simulate having multiple Julia scripts running (from the same thread), I >>> got crashes, which I was able to fix using e.g. jl_gc_preserve(mMyState); >>> and appropriate matching jl_gc_unpreserve() calls. >>> >>> I see these functions have been removed from the latest Julia version. >>> >>> Is there an alternative that allows Julia values to be retained in a C++ >>> app across gc calls? >>> >> >> Copy from my reply on github >> >> > This never works in the way you think it did. For keeping a value live, >> put it in a rooted global array. >> >> >> > I'm not saying this is the best way to implement Yichao's suggestion, but > here is how it's done in CxxWrap.jl: > > https://github.com/barche/CxxWrap.jl/blob/master/deps/src/cxx_wrap/type_conversion.hpp#L27-L38 > > The array is allocated and rooted using jl_set_const here: > > https://github.com/barche/CxxWrap.jl/blob/master/deps/src/cxx_wrap/cxx_wrap.cpp#L14-L28 > > Cheers, > > Bart >