From: Charles Mills Date: 2005-04-05T00:34:43+09:00 Subject: Re: Extension question > Are there any general rules of thumb that you use when writing extensions? http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/47700 You shouldn't be able to cause your extension to seg fault from Ruby. That may sound like a joke, but I just mean using StringValue, NUM2LONG, etc before you starting using Ruby objects in C. > > My first problem was trying to figure out what should remain Ruby code > and what should be moved out to C. For example, if I opened the file > that contained binary data in Ruby, how could I "get" to that data > using a FILE pointer in C? Or should I just pass the filename to the > C extension? > You can do either. IMO it depends on the layout of the file. If your reading line by line you can do this easily using the rb_io_* functions found in intern.h. If your going to be moving the file position around, using fgetc/ungetc, or reading into C structs it may be easier to use the stdio functions directly. -Charlie