Re: Calculating size for MIDIPacketListAdd
Re: Calculating size for MIDIPacketListAdd
- Subject: Re: Calculating size for MIDIPacketListAdd
- From: Kurt Revis <email@hidden>
- Date: Wed, 18 Sep 2002 20:46:45 -0700
On Wednesday, September 18, 2002, at 06:50 PM, email@hidden wrote:
I'm trying to add a packet to a MIDIPacketList but the function needs
to know
the length of the packet list to which I'm trying to add.
Why can't the add function figure this out for itself (the calculation
doesn't look easy)?
The idea is that you have a fixed-size buffer of data, in which the
MIDIPacketList is stored. MIDIPackets (and thus MIDIPacketLists) can
vary in size. You want to tell MIDIPacketListAdd() the total size of
the buffer, so it doesn't write over the end, and stomp on whatever
random data is after it.
If you are just using a struct MIDIPacketList, then sizeof(struct
MIDIPacketList) will tell you the size. If you allocated memory, you
should know how big it was.
Finally can/should I even be trying to modify the PacketList that came
into my read proc? I know it's const but the examples cast it away :-)
You're probably OK. The only case in which this could break would be
if you have multiple input ports which are listening to the same
endpoint in the same application. In that case, it's possible that
CoreMIDI could call the input callback for each port with the same
packet list. (I don't know if it does or not, though.) It's fairly
unlikely that you are going to do this.
(Of course, you shouldn't rely on the packet list staying valid after
your callback returns. CoreMIDI can do whatever it wants to that memory
afterwards.)
If you really want to be safe, you can copy the contents of the packet
list. You can walk through each packet in the packet list to find its
total size. It's a little bit of a pain but you should only have to
write it once.
Would it be better to create my own packet list and copy the data into
there? But then
there's no nice dispose function to throw it away...
Just malloc() some memory, cast it to a (struct MIDIPacketList *), use
it, and free() it when you're done.
--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.