From: Elias Athanasopoulos Date: 2004-03-30T01:32:31+09:00 Subject: Re: Obtaining size of Ruby objects in C On Thu, Mar 25, 2004 at 08:54:34PM +0900, Christopher C.Aycock wrote: > I'm writing a wrapper over a C function for Ruby. Because the Ruby > function has dynamic features that the C version does not, I can't use > SWIG and have to write everything by hand. I was wondering if anyone > knows how to obtain the size (in bytes) of a single element of an array. I can't understand why SWIG fails. > For example, if I have an array of type T, then sizeof (T) would give > me what I'm looking for. The C wrapper is being passed a VALUE type > parameter that should represent an array from the user. Is there a way > to determine the type of the array, plus the number of bytes of that > type? You have to check its of the array's elements if you want to find the overall memory stamp of the array, but still I can't figure out why you want to do such a thing. Also, there isn't *a type* of a Ruby array. This is true, in a sense, only for homogeneous arrays, but Ruby arrays are not, in general, homogeneous (i.e. different types can co-exist in a single array). Regards, -- University of Athens I bet the human brain Physics Department is a kludge --Marvin Minsky