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?


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to