[Gc] a bug in v.7.1 ?

Glauco Masotti glauco.masotti at libero.it
Tue Mar 8 00:39:19 PST 2011


First of all let me thank all those who have contributed to clarify this issue.
I am also glad that this thing will probably be highlighted in the documentation.

Some final (perhaps) remarks:

> POinters to objects must point to within the object, or 1 item past the end.
>
1 item past the end is fine? I forgot this detail. (***)

> Note that even with a traditional malloc(), you can't pass the return
> value to free() â?" you have to pass ptr+nl-NR_END (i.e. v).
>
In fact the corresponding free for use with MMM is defined as:

void free_vector(float *v, long nl, long nh)
  /* free a float vector allocated with vector() */
{
  free((FREE_ARG) (v+nl-NR_END), (nh-nl+1+NR_END)*sizeof(float));
}

> You need to make sure that v is stored somewhere that the GC can see
> it. Probably the cleanest way is to add an extra argument to vector in
> which you pass the address of a local variable which you can
> subsequently ignore. This will work unless the array is passed out
> from the function that allocates it.
>
Hmm...

> Or, you can rewrite your code to only use arrays where nl is <= NR_END, as you discovered.
>
I think this is preferable. The complications of the other case are not worth the trouble.
In principle, although somewhat weird, subscripts could even go negative, as long as (***) is satisfied.
But a safe and reasonable assumption could certainly be: 0 <= nl  <= NR_END (in practice 0 or 1 :-|

--- Glauco Masotti






More information about the Gc mailing list