Hi, Thanks for help.
OK, I've created a new ticket as below. https://www.macruby.org/trac/ticket/1080 Thanks&Regards. kyossi >Hi, >There is no way to do that for now. Could you file a ticket? I will introduce >#size on C structs classes. >NSRect.size in MacRuby would be the same as sizeof(NSRect) in C. >Laurent On Dec 24, 2010, at 12:19 PM, kyossi wrote: > Hi, > > I'm trying to write some app in MacRuby with CoreAudio framework. > > I've notices some framework's C-function require pointer manipulation, > and for some cases, I need calculate size of C-struct, but don't know > how to get sizeof(struct Foo). > > Is there any way to calculate size of C-struct in MacRuby? > > For example, to obtain available formats of audio stream,I have to > call AudioStreamGetPropertyInfo() at first. > > extern OSStatus AudioStreamGetPropertyInfo( > AudioStreamID inStream, > UInt32 inChannel, > AudioDevicePropertyID inPropertyID, > UInt32*outSize, > Boolean*outWritable); > > if I specify kAudioStreamPropertyAvailableVirtualFormats as 3rd > argument(inPropertyID), > outSize gives me total required byte size for [an array of > AudioStreamRangedDescription struct] which describe available formats. > > Then, AudioStreamGetProperty() will fill [an array of > AudioStreamRangedDescription struct] with available formats > > extern OSStatus AudioStreamGetProperty( > AudioStreamID inStream, > UInt32 inChannel, > AudioDevicePropertyID inPropertyID, //again use > kAudioStreamPropertyAvailableVirtualFormats > UInt32*ioPropertyDataSize, > void*outPropertyData); //filled by API > > http://developer.apple.com/library/mac/#documentation/MusicAudio/Reference/CACoreAudioReference/AudioHardware/CompositePage.html > > So, I need to write some code like > > framework "CoreAudio" > def getAvailableFormats(stream, channel) > > pSize = Pointer.new("I") > ret = AudioStreamGetPropertyInfo( stream , channel, > KAudioStreamPropertyAvailableVirtualFormats, pRequiredSize, nil) > requiredSize = pSize[0] > > howmany = ??? # how to get reqired length of array? in C: howmany > = requiredSize / sizeof( AudioStreamRangedDescription ) > pAudioStreamRangedDescription = > Pointer.new("{AudioStreamRangedDescription={AudioStreamBasicDescription=dIIIIIIII}{AudioValueRange=dd}}", > howmany) > > > ret = AudioStreamGetProperty(stream, channel, > KAudioStreamPropertyAvailableVirtualFormats, pRequiredSize, > pAudioStreamRangedDescription) > ... > end > > > Of course I could calculate sizeof( AudioStreamRangedDescription) > manually but it's annoying. > Is there any convenient way? > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel