From: Brian Candler Date: 2011-04-02T07:00:20+09:00 Subject: Re: Method Call from inside a file. Tridib Bandopadhyay wrote in post #990442: >> I don't know what you mean by "acting like a library function". > > I mean to say that I am trying to write a function which will allow the > users to free the allocated memory by themselves rather than doing it by > Garbage Collection. So I need a syntax like that of C > > free(variable); I believe you're writing C code for use by ruby. Ruby doesn't provide users with any free() method; users rely on garbage collection. So if you want to extend ruby in C, you need to make your code work with ruby's garbage collection. A ruby user can *prevent* something from being garbage collected, if they want, just by holding a reference to it (e.g. in a global variable). If you read http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html then you'll find whole sections on memory allocation and garbage collection. Look at Data_Make_Struct and Data_Wrap_Struct in particular. If you won't read the documentation, then I'm afraid you're on your own. Of course, if you're writing C to be called from C (rather than from ruby) then you can have people call your own allocate and free routines. But this is not a forum about writing C programs. -- Posted via http://www.ruby-forum.com/.