> Allocate `giarg' with `(malloc 'nonatomic ...)` and never install a non-pointer value into it.
When I allocate giarg, I don't know yet, what type it will store. It is _union... > Allocate the string's memory with `(malloc 'atomic-interior ...)` So it should be something like (struct giarg (ptr string-ptr)). And I should set giarg-string-ptr whenever I ptr-set! giarg-ptr _string. I think, it is best option. Thank you! Воскресенье, 1 сентября 2013, 11:10 -06:00 от Matthew Flatt <mfl...@cs.utah.edu>: >You're right --- the string can be GC'ed at any time. > >There are a few ways to solve the problem: > > * Allocate `giarg' with `(malloc 'nonatomic ...)` and never install a > non-pointer value into it. > > * Allocate the string's memory with `(malloc 'atomic-interior ...)` > and arrange for that memory to be referenced from some GC-visible > place for as long as it can be referenced by `giarg`. > > * Allocate the string's memory with `(malloc 'raw ...)` and explicitly > `free` it when `giarg` is no longer used. > >At Sun, 01 Sep 2013 17:38:26 +0400, Roman Klochkov wrote: >> (define _giarg (_union _bool _int8 _uint8 _int16 _uint16 >> _int32 _uint32 _int64 _uint64 >> _float _double _long _ulong _pointer _string)) >> >> (define giarg (malloc _giarg)) (ptr-set! giarg _string "Test string") >> >> --- >> >> It works. But I'm afraid, that string maybe allocated temporary and will be >> GC'ed at any time. Or _union keep _string pointer inside? > -- Roman Klochkov
____________________ Racket Users list: http://lists.racket-lang.org/users