• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calculating size for MIDIPacketListAdd
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Calculating size for MIDIPacketListAdd
      • From: email@hidden
References: 
 >Calculating size for MIDIPacketListAdd (From: email@hidden)

  • Prev by Date: AudioFile.h and FSRef??
  • Next by Date: Re: Playing 2 or more audio data simultaneously
  • Previous by thread: Calculating size for MIDIPacketListAdd
  • Next by thread: Re: Calculating size for MIDIPacketListAdd
  • Index(es):
    • Date
    • Thread