Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another Threading Question



On Jun 15, 2007, at 8:27 AM, Dave wrote:

On 13 Jun 2007, at 15:15, George Warner wrote:

On Tue, 12 Jun 2007 14:21:30 +0100, Dave <email@hidden> wrote:
If am using MPCreateTask() to a create a task that is used to process
a movie file. The results are stored in a big buffer (maybe 20MB in
size). How can I pass a this buffer from the task I created to the
creating task?

There's a programming axiom that says that you should always free memory in
the same function that allocates it. Following that I'd advise that you to
allocate the memory in the creating task and pass it to the MP thread
instead;


Is it ok to use malloc() and just pass the buffer back via a Global?

NO. ;-)

So, what method would you recommend instead?

I'm jumping into the middle of this thread, so apologies in advance if I missed something crucial.


If you're allocating the buffer before calling MPCreateTask, you could pass the buffer pointer (and more) to the task via the "parameter" parameter of MPCreateTask.

Since you mentioned that you're writing a plug-in, you could also store the buffer pointer as part of your plug-in's instance variables, if supported. Plug-in APIs usually provide a mechanism for you to do that (for example, a userData field in a parameter block passed to the plug-in: you malloc storage for a struct and store it in the PB where it's available for future calls). That way you don't run into the issues of multiple accessors of a global.

steve

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >re: Another Threading Question (From: George Warner <email@hidden>)
 >Re: Another Threading Question (From: Dave <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.