From: Sean Middleditch Date: 2002-05-04T14:04:57+09:00 Subject: Re: Is ruby ready for prime time? On Sat, 2002-05-04 at 00:50, dagang wang wrote: > I am writing a test script for a c api. Following is a piec e of pseudo-code > > .... > MyStruct* pRes; > unsigned long length; > getData(&pRes, &length); > // a check shows pRes is initialized ok > VALUE arr=rb_str_new2("text") // I suppose some memory allocation is done > here > //oops. a check shows pRes is corrupted > > I encountered many such problems in my development related to memory > management. I have the feeling that Ruby is not ready for prime time. At > least for the Ruby-C extension part. I wonder if anyone else has the same > experience and knows how to get around it. Um, I'd say that's a problem with *your* code, not Ruby. Many many many other C extensions work perfectly well. One thing to remember is that Ruby uses a GC for memory management. If you allocate one Ruby value, then a second, there is a chance on the second allocation that the first one will be deleted (because the second may trigger a run of the GC, and that will detect that nothing references the first value, and delete it). Thus, you need to make sure after each value allocation that Ruby knows you are using it. Depending on what you're doing, there are different ways of doing that. I'd recommend reading the documentation, because that should all be fairly clear once it's read. And, not to nitpick, but a subject like "is ruby ready for prime time?" is not at all the best thing to do - I'd try something like "I'm having trouble with memory mangement." The first is offensive with no good reason, the second is actually relevant to your e-mail. ^,^ > > Doug > >