Re: how to make a task less cpu intensive
Re: how to make a task less cpu intensive
- Subject: Re: how to make a task less cpu intensive
- From: Jens Alfke <email@hidden>
- Date: Fri, 28 Dec 2012 10:36:02 -0800
On Dec 28, 2012, at 9:40 AM, Nick Rogers <email@hidden> wrote:
> I have a tree in memory (all nodes malloc'ed blocks) and when I start freeing this large tree, I traverse the tree and free all nodes.
> This becomes cpu intensive and so the progress bar on my sheet doesn't animate.
>
> In similar other situations the progress bar animates, when different code is executed in the background.
You’re freeing the tree on a background thread, and the UI thread is locking up? That shouldn’t happen.
My first answer to any sort of performance or why-does-this-thread-block question is “sample it”. Use Instruments or Activity Monitor or the ‘sample’ tool to see what’s going on inside while in this state. It’s possible that the freeing is happening on the main thread by mistake, or the freeing code is holding some lock that the main thread gets stuck waiting for.
You must have a vast number of tree nodes, if freeing the tree takes a macroscopic amount of time. Are they all the same size? If so, you can use a custom allocator for them (as long as they’re C structs or C++ objects); that’ll be much faster than malloc.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden