From: Ara.T.Howard@... Date: 2005-05-17T08:50:30+09:00 Subject: Re: rb_gc_mark question --8323328-1912837268-1116286630=:13494 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1912837268-1116286630=:13494" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1912837268-1116286630=:13494 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 17 May 2005, Nikolai Weibull wrote: > Ara.T.Howard wrote: > >> static VALUE >> convertgslmatrixToRubyMatrix (gsl_matrix * dm) >> { >> int i, j; >> VALUE result; >> VALUE rows =3D rb_ary_new (); >> for (i =3D 0; i < dm->size1; i +=3D 1) >> { >> VALUE currow =3D rb_ary_new (); >> rb_gc_mark (currow); >> rb_ary_push (rows, currow); >> for (j =3D 0; j < dm->size2; j +=3D 1) >> { >> double val =3D gsl_matrix_get (dm, i, j); >> VALUE rval =3D rb_float_new (val); >> rb_ary_push (currow, rval); >> } >> } >> result =3D rb_funcall (cMatrix, rb_intern ("rows"), 2, rows, Qnil); >> return result; >> } > > I don=E2=80=99t understand why you need to rb_gc_mark those values. They= =E2=80=99re > pointed to by objects on the stack, so a GC sweep won=E2=80=99t remove th= em. > Neither of the volatile specifiers in the original are needed either, as > you write (or I am definitely missing something). I don=E2=80=99t see ho= w they > would be optimized away anyway. Well, actually, the 'result' variable > should be optimized away :-), just return the result of the rb_funcall > immediately. > > Perhaps I don=E2=80=99t understand what you want to do here, > nikolai just wanting you to confirm exactly what i was thinking. the code was so aggressive with rb_gc_mark that i started thinking i might be missing something! you'll note my version didn't have them at all... so we are in total agreement - i'm reading the code for someone else and ju= st trying to figure out what they thought they were doing. needless to say th= is extension has some memory issues ;-) thanks for the clarification. cheers. -a --=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D | 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 acceptin= g | that they pass away. --aitken roshi =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D --8323328-1912837268-1116286630=:13494-- --8323328-1912837268-1116286630=:13494--