[MacRuby-devel] MacRuby equivalent to C sizeof(struct Foo)
Laurent Sansonetti
lsansonetti at apple.com
Sun Dec 26 17:38:59 PST 2010
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 at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101226/25eb564b/attachment.html>
More information about the MacRuby-devel
mailing list