From: Ara.T.Howard@... Date: 2005-05-17T09:30:31+09:00 Subject: Re: rb_gc_mark question On Tue, 17 May 2005 nobu.nokada@softhome.net wrote: > Hi, > > At Tue, 17 May 2005 07:40:31 +0900, > Ara.T.Howard wrote in [ruby-talk:142850]: >> i reading some code attm that goes: >> >> static VALUE convertgslmatrixToRubyMatrix(gsl_matrix *dm) >> { >> int i, j; >> volatile VALUE result; >> assert(dm); >> // printf("Trying to convert dm %p\n", dm); >> // printf("With size %d, %d\n", dm->size1, dm->size2); >> volatile VALUE rows = rb_ary_new(); >> rb_gc_mark(rows); >> for (i = 0; i < dm->size1; i += 1) { >> volatile VALUE currow = rb_ary_new(); >> rb_gc_mark(currow); >> rb_ary_push(rows, currow); > > GC may run while resizing rows, however many platforms don't > have the problem. And rb_gc_mark() isn't sufficient in theory > but volatile with currow avoids it, so rb_gc_mark() isn't > needed here at all. why does it matter if the GC runs while re-sizing rows? it seems like rows would still have references to all the old rows and the new one would be added? or are you saying that, without volatile currow could get gc'd when rows got resized? i guess i can see that. still how would volatile help that? >> for (j = 0; j < dm->size2; j += 1) { >> double val = gsl_matrix_get(dm, i, j); >> VALUE rval = rb_float_new(val); >> rb_gc_mark(rval); > > Therefore volatile before rval is better than rb_gc_mark() also > here. you are saying ONLY volatile and no rb_gc_mark then? > >> rb_ary_push(currow, rval); >> } >> } >> result = rb_funcall(cMatrix, rb_intern("rows"), 2, rows, Qnil); >> rb_gc_mark(result); > > No meanings at all. right. thanks. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================