Re: NSController controllerEditor:didCommit :… exception

2010-11-14 Thread Kyle Sluder
On Sun, Nov 14, 2010 at 11:10 PM, vincent habchi  wrote:
>
> Quincey, Kyle:
>
> >> While it is true the MOC is not initialized at this point, I don't see 
> >> what could cause this message appear at such an early stage. Can it be 
> >> linked somehow with the initialization of a static object embedded in the 
> >> "MainMenu" NIB?
> >
> > If, as it happens, your MainMenu.nib contains a window, make sure that 
> > "visible at launch" isn't checked.
>
> Upon further examination, I have a NSArrayController in entity mode in the 
> MainMenu NIB, so I think the error is caused by its initialization while no 
> MOC is yet created. I'll try to move it in a separate NIB or create it 
> programatically.

The main menu nib is kind of funny. It's loaded differently (or at
least at a different time) than the other nibs. It's much more
sensitive to timing issues like this.

Who provides the MOC for the controller (another object in the nib?),
and how is it provided (bindings, -setManagedObjectContext:)?

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSController controllerEditor:didCommit :… exception

2010-11-14 Thread vincent habchi
Quincey, Kyle:

>> While it is true the MOC is not initialized at this point, I don't see what 
>> could cause this message appear at such an early stage. Can it be linked 
>> somehow with the initialization of a static object embedded in the 
>> "MainMenu" NIB?
> 
> If, as it happens, your MainMenu.nib contains a window, make sure that 
> "visible at launch" isn't checked.

Upon further examination, I have a NSArrayController in entity mode in the 
MainMenu NIB, so I think the error is caused by its initialization while no MOC 
is yet created. I'll try to move it in a separate NIB or create it 
programatically.

Cheers
Vincent___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Is App in Resources App Bundle Evil?

2010-11-14 Thread Kyle Sluder
On Sun, Nov 14, 2010 at 9:55 AM, kalexm  wrote:

> Hello all,
>
> I'm new to the list and somewhat new to OSX (not iphone!) development. I
> spent ten years most of my time in java so it was a hurdle..
>
> I am currently developing an app (APP-A) which does PDF manipulation. I
> have a second app (APP-B), that provides a PDF Viewer which is older.
> APP-A depends on APP-B as it uses APP-B for viewing manipulated PDFs. APP-B
> is independent from APP-A.
> I could put both apps into Applications. But if a User don't know what
> APP-B is for as he might only wan't APP-A but didn't see the dependency, he
> might delete APP-B and APP-A cannot work properly anymore.
>
> To solve this I put APP-B into the resources of APP-A, and it works to
> launch the app from this directory. I have not found any documentation from
> apple or mailing-lists if this is unwanted, problematic or somewhat evil!?
> The launchd finds the 'hidden' APP-B and behaves as expected...
>
> Is this allowed and recommendable, or how could I solve this alternatively
> and I don't want to merge the apps!?
>

The code signing in-depth technote (TN2206) advises against using Resources
for this. It suggests putting the helper app bundles in the Contents folder,
and single-file helper binaries directly inside Contents/MacOS.
http://developer.apple.com/library/mac/#technotes/tn2007/tn2206.html%23TNTAG19

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: libsvn_client for IOS

2010-11-14 Thread Kyle Sluder
On Sun, Nov 14, 2010 at 11:51 AM, James West  wrote:

> I'd like to add support for svn to my ios project, but I notice that
> libsvn_client is not available for ios through Frameworks > Add > Existing
> Framework.
>
> My question is two-fold: 1) Is there a method by which I can link against
> libsvn_client in an ios application and 2) If not, are there any issues
> with
> compiling and linking against libsvn from source?
>

You'll have to statically link it as iOS doesn't support dylibs. That
necessitates compiling from source.

I don't know of any specific issues with libsvn_client on iOS, but I
wouldn't be surprised if there are a few (either in libsvn_client or the
Apache Portable Runtime on which libsvn_client relies).

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Is App in Resources App Bundle Evil?

2010-11-14 Thread kalexm
Hello all,

I'm new to the list and somewhat new to OSX (not iphone!) development. I spent 
ten years most of my time in java so it was a hurdle..

I am currently developing an app (APP-A) which does PDF manipulation. I have a 
second app (APP-B), that provides a PDF Viewer which is older.
APP-A depends on APP-B as it uses APP-B for viewing manipulated PDFs. APP-B is 
independent from APP-A.
I could put both apps into Applications. But if a User don't know what APP-B is 
for as he might only wan't APP-A but didn't see the dependency, he might delete 
APP-B and APP-A cannot work properly anymore.

To solve this I put APP-B into the resources of APP-A, and it works to launch 
the app from this directory. I have not found any documentation from apple or 
mailing-lists if this is unwanted, problematic or somewhat evil!? The launchd 
finds the 'hidden' APP-B and behaves as expected...

Is this allowed and recommendable, or how could I solve this alternatively and 
I don't want to merge the apps!?

best,

Alex___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


libsvn_client for IOS

2010-11-14 Thread James West
I'd like to add support for svn to my ios project, but I notice that
libsvn_client is not available for ios through Frameworks > Add > Existing
Framework.

My question is two-fold: 1) Is there a method by which I can link against
libsvn_client in an ios application and 2) If not, are there any issues with
compiling and linking against libsvn from source?

Thanks!

-- James
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Maths package for 128/256 bit integers?

2010-11-14 Thread Dave DeLong
I wrote some wrappers around the OpenSSL bignum library, available here:

https://github.com/davedelong/CHMath

Cheers,

Dave DeLong

On Nov 14, 2010, at 4:14 PM, William Squires wrote:

> I know some crypto algorithms use 128 or up to 256 bit keys - I'm hoping that 
> means there's a maths package (in C or ObjC) that'll provide for computations 
> (addition, subtraction, multiplication, division, and modulus, at least...) 
> and a way to convert them to<->from NSStrings. Anyone know of any? I'm trying 
> to rewrite an algorithm I made for NSUIntegers to use ever larger values for 
> cryptanalysis.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
> 
> This email sent to davedel...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Maths package for 128/256 bit integers?

2010-11-14 Thread Dave Carrigan
Your best bet is probably Gnu MP. It can do whatever precision you want and has 
a fairly large community of developers. I'm sure there are Objective-C wrappers 
available for it as well.

On Nov 14, 2010, at 3:14 PM, William Squires wrote:

> I know some crypto algorithms use 128 or up to 256 bit keys - I'm hoping that 
> means there's a maths package (in C or ObjC) that'll provide for computations 
> (addition, subtraction, multiplication, division, and modulus, at least...) 
> and a way to convert them to<->from NSStrings. Anyone know of any? I'm trying 
> to rewrite an algorithm I made for NSUIntegers to use ever larger values for 
> cryptanalysis.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/dave%40rudedog.org
> 
> This email sent to d...@rudedog.org

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Maths package for 128/256 bit integers?

2010-11-14 Thread William Squires
I know some crypto algorithms use 128 or up to 256 bit keys - I'm  
hoping that means there's a maths package (in C or ObjC) that'll  
provide for computations (addition, subtraction, multiplication,  
division, and modulus, at least...) and a way to convert them to<- 
>from NSStrings. Anyone know of any? I'm trying to rewrite an  
algorithm I made for NSUIntegers to use ever larger values for  
cryptanalysis.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


unit test exit's abnormally with code 5

2010-11-14 Thread Shane
I'm trying to put a unit test together, so I've created a new target,
added my files to compile and frameworks to link to, then commented
out all of my code to where I have an empty setUp, tearDown, and
testFunc, but still getting the following error.

/Developer/Tools/RunPlatformUnitTests.include:419: note: Running tests
for architecture 'x86_64' (GC OFF)
objc[13117]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
2010-11-14 16:22:29.300 otest-x86_64[13117:903] The test bundle at
/Users/shane/Projects/HHI/hhi/build/Release/UnitTests.octest could not
be loaded because its Objective-C runtime information does not match
the runtime information required by the test rig.  This is likely
because the test rig is being run with Objective-C garbage collection
disabled, but the test bundle requires Objective-C garbage collection.
 To enable Objective-C garbage collection for the test rig, run it in
an environment without the OBJC_DISABLE_GC environment variable.
2010-11-14 16:22:29.307 otest-x86_64[13118:203] *** NSTask: Task
create for path
'/Users/shane/HHI/Projects/HHI/hhi/build/Release/UnitTests.octest/Contents/MacOS/UnitTests'
failed: 22, "Invalid argument".  Terminating temporary process.
/Developer/Tools/RunPlatformUnitTests.include:451: error: Test rig
'/Developer/Tools/otest' exited abnormally with code 5 (it may have
crashed).shane

My unit test is an obj-c file with the *.mm extension because I'm
testing obj-c as well as some c++ calls to a dyld file.

Guess I'm having a hard time interpreting this error.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread James Bucanek
Antonio Nunes  wrote (Sunday, 
November 14, 2010 11:18 AM -):



The sweet spot may of course differ on different machines and systems, so that
is where setMaxConcurrentOperationCount comes in handy.


Not only will it vary from machine to machine, but it's going to 
very from minute to minute depending on what other I/O activity 
the user is doing, how much unused RAM is available (for disk 
caching), and other factors.


If you need the absolute maximum performance, then it's going to 
have to be tweaked individual for every system. Otherwise, just 
profile the performance on a variety of systems and pick a 
concurrency count that looks like the best compromise.


--
James Bucanek

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread Ken Thomases
On Nov 14, 2010, at 12:39 PM, Antonio Nunes wrote:

> On 14 Nov 2010, at 16:25, Ken Thomases wrote:
> 
>> -[NSProcessInfo activeProcessorCount]
> 
> I see there is also processorCount. The docs totally don't explain what the 
> difference is. Is an active processor one that is available for processing, 
> but not necessarily being used, or is it one that is definitely in the 
> process of churning bits?

CPU cores can be disabled.  For example, 
/Developer/Extras/PreferencePanes/Processor.prefPane can disable cores.

-processorCount returns how many cores are present, -activeProcessorCount 
returns how many of those are enabled.

Cheers,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSController controllerEditor:didCommit :… exception

2010-11-14 Thread Quincey Morris
On Nov 14, 2010, at 03:32, vincent habchi wrote:

> While it is true the MOC is not initialized at this point, I don't see what 
> could cause this message appear at such an early stage. Can it be linked 
> somehow with the initialization of a static object embedded in the "MainMenu" 
> NIB?

If, as it happens, your MainMenu.nib contains a window, make sure that "visible 
at launch" isn't checked.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread Antonio Nunes
On 14 Nov 2010, at 16:25, Ken Thomases wrote:

> The system can't predict the future.  When an operation is pending in a 
> queue, there's no way for the system to know if it's going to be CPU 
> intensive, memory intensive, and/or I/O intensive.
> 
> Let's suppose the system primarily governs its thread pool based on available 
> CPU time.  Let's also suppose that your operations start with some blocking 
> I/O but then switch to computation.  When there are operations queued, but 
> most of the already-running operations are blocked doing I/O, then the CPU 
> may have idle capacity.  So, the system starts another operation (or 
> several).  It will have effectively "overbooked" the CPU -- in short order, 
> as I/O requests are satisfied, there will be more operations doing CPU-based 
> computation then there is CPU capacity to handle them.
> 
> It's also the case that disk I/O degrades significantly with contention.  So, 
> even just having a bunch of I/O-intensive operations queued can burden the 
> system, even while there's plenty of spare CPU and memory capacity.

Ok, thanks for the clear explanation. You've probably hit the nail on the head. 
The tasks do some initial computation, but that is really, really fast. The 
next bit is writing the result to a file on disk, and that is really slow, 
especially with big documents.

> However, one approach to working around the system's limitations is to 
> separate your operations into pure I/O operations and pure CPU operations.  
> (If one logical operation involves both, you can split it and use 
> dependencies to have the two halves run in the appropriate order.)

I'm not sure that is an option, but I don't think that matters anyway, since 
the computational part of the operation is almost negligible. It's writing the 
data to disk that is most likely causing contention.

>> Also, is there a way to find out the number of cores on a machine so that I 
>> can set that as a hard limit of number of operations on an NSOperationQueue?
> 
> -[NSProcessInfo activeProcessorCount]

Short and sweet. Thanks!

I see there is also processorCount. The docs totally don't explain what the 
difference is. Is an active processor one that is available for processing, but 
not necessarily being used, or is it one that is definitely in the process of 
churning bits?

> It appears that your program is launching copies of itself to process 
> individual files.  I suspect you're "bringing the whole system to a crawl" by 
> a fork bomb.  Have you checked that your program is not 
> infinitely-recursively launching subprocesses?

Yes, it is not recursively launching subprocesses.

> Also, why are you re-running your program in a subprocess, instead of just 
> having your operation do the work directly?  (I suspect you do it that way in 
> case processing of a particular file causes a crash.  You want to limit the 
> crash to just the process handling that file.)

Well, that is one benefit of this approach, but it wasn't the main reason. It 
looks though, like I will need to re-asses my decision and see if i can get 
better results by having the operation doing the work directly.

> Have you considered letting launchd monitor the directories, launch your 
> daemon, and deal with any crashes?

Nope. Did not even know that was possible. Another interesting option to look 
into.

> I'll also say that having NSOperations launch an NSTask and block waiting for 
> it to exit is nearly a worst case scenario for NSOperationQueue.  It has a 
> thread pool with idle threads, so it figures it can pull a new operation off 
> the queue to start it with minimal new resources.  That operation not only 
> monopolizes the thread, it does effectively nothing with it. Instead, it 
> launches a whole separate process, which is a significant use of new 
> resources.

Yes, that would explain the behaviour I'm seeing quite well, I believe. Back to 
the drawing board. Thanks so much for so clearly expounding the issues involved.

António

---
Don't believe everything you think
---




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread Antonio Nunes
On 14 Nov 2010, at 16:16, James Bucanek wrote:

> NSOperationQueue uses Grand Central Dispatch, which will attempt to 
> load-balance the number of running operations based on _CPU_ resources. 
> However, that doesn't mean GCD will (or even can) automatically find the most 
> efficient run schedule for your code.

Ok, understood.

>> My question: how can I ensure that no more operations are launched at any one
>> time than the system can handle?
> 
> -[NSOperationQueue setMaxConcurrentOperationCount:]

My bad. I wasn't totally clear in my description there. I actually already 
deploy that as a user definable option, and it certainly works. (Or, well, a 
tester just told me that if he specifies more than 9 operations, then the limit 
doesn't work. I'll have to check that out. Might be some silly mistake of mine. 
Don't know yet.) I was thinking along the lines of how I can ensure that the 
system knows that launching more tasks concurrently would be a bad thing when 
resources are already being maxed out. Ken's answer provides some very useful 
deeper info on the hows and whys here.

> Personally, if your operation is mostly I/O bound, the best solution is to 
> set maxConcurrentOperationCount to 1 and run the operations sequentially. The 
> biggest problem in trying get better performance from I/O heavy processes is 
> the HD trashing that occurs when you have more than one working 
> simultaneously. This can easily mean that two operations will run slower than 
> one.

I know from testing that running more than one operation can be quite 
beneficial, but the operations are I/O heavy, especially at the end, so this 
may well be a factor, where the sweet spot lies around a low number of 
concurrent operations. The sweet spot may of course differ on different 
machines and systems, so that is where setMaxConcurrentOperationCount comes in 
handy. 

Thanks for all the useful info.

António


It is better to light a candle than to curse the darkness




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSController controllerEditor:didCommit: … exception

2010-11-14 Thread Kyle Sluder
On Nov 14, 2010, at 3:32 AM, vincent habchi  wrote:

> Hi everybody,
> 
> this is a minor annoyance but I'm still puzzled about it.
> 
> When I launch my application, after -applicationWillFinishLaunching: 
> completes, I get an exception started by -[NSController 
> controllerEditor:didCommit:contextInfo:]. I cannot get a decent traceback to 
> pinpoint what object is causing the exception, since it is ultimately raised 
> from _NSFireDelayedPerform. It has somehow something to do with Core data, 
> since ignoring it brings up the message "Cannot perform operation without a 
> managed object context" (and no fatal error ensues).

You could break on all the NSObject performSelector: variants. Perhaps add a 
breakpoint action that checks if the selector is equal to whatever immediately 
follows the _NSFireDelayedPerform.


> 
> While it is true the MOC is not initialized at this point, I don't see what 
> could cause this message appear at such an early stage. Can it be linked 
> somehow with the initialization of a static object embedded in the "MainMenu" 
> NIB?

Sure. Where are you giving your controllers their MOC?

--Kyle Sluder___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: More stoopid questions...

2010-11-14 Thread Bill Cheeseman

On Nov 14, 2010, at 10:40 AM, Matt Neuburg wrote:

> We all did all those steps manually for years and years, on every single 
> application we wrote. Finally Apple realized they could save us some steps 
> and wrote it into the template. Since the purpose of the provided instance is 
> to function as the app's delegate, Delegate appears in the name.


And to carry Matt's story a little further, it is still up to you to decide 
what more you want to put in the MainMenu nib file. The template already 
includes File's Owner, First Responder, the application object, a menubar with 
menus, and a window. I just started a new application from this template, and 
the first thing I did was to add a "MainWindowController" object to the nib 
file, designate a new MainWindowController class as its owner, and connect up 
various outlets so they could all say hello to each other. I am now putting 
code to control the window into the MainWindowController class in order to 
maintain a certain degree of encapsulation, although I also send a couple of 
messages to the window from the appDelegate for convenience.

--

Bill Cheeseman - b...@cheeseman.name

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread Ken Thomases
On Nov 14, 2010, at 3:58 AM, Antonio Nunes wrote:

> I'm developing a daemon to run tasks as files get dropped into a folder. When 
> a new file is detected, a new operation gets put onto the daemon's operation 
> queue. The operation launches a task and waits for it to finish, then the 
> operation exits.
> 
> The issue I am seeing is that the operation queue appears to indiscriminately 
> run operations as they are added to the queue, regardless of system 
> resources, thus bringing the whole system to a crawl. I thought, from reading 
> the documentation, that the queue would be intelligent about how many 
> operations it would have running at the same time, depending on system 
> resources such as number of cores and available memory.

The system can't predict the future.  When an operation is pending in a queue, 
there's no way for the system to know if it's going to be CPU intensive, memory 
intensive, and/or I/O intensive.

Let's suppose the system primarily governs its thread pool based on available 
CPU time.  Let's also suppose that your operations start with some blocking I/O 
but then switch to computation.  When there are operations queued, but most of 
the already-running operations are blocked doing I/O, then the CPU may have 
idle capacity.  So, the system starts another operation (or several).  It will 
have effectively "overbooked" the CPU -- in short order, as I/O requests are 
satisfied, there will be more operations doing CPU-based computation then there 
is CPU capacity to handle them.

It's also the case that disk I/O degrades significantly with contention.  So, 
even just having a bunch of I/O-intensive operations queued can burden the 
system, even while there's plenty of spare CPU and memory capacity.

There's discussion of a related issue, this time having to do with Grand 
Central Dispatch, at Mike Ash's blog:
http://www.mikeash.com/pyblog/friday-qa-2009-09-25-gcd-practicum.html

> Since this doesn't seem to be the case, I have to assume something is not 
> quite right with my implementation.

Not necessarily.

However, one approach to working around the system's limitations is to separate 
your operations into pure I/O operations and pure CPU operations.  (If one 
logical operation involves both, you can split it and use dependencies to have 
the two halves run in the appropriate order.)  Schedule the I/O operations to a 
queue with a fairly small maximum concurrent operations limit.  If you want to 
get really fancy, you might have separate I/O queues for each device (e.g. 
disk) to maximize parallelism.  Schedule the CPU-intensive operations onto 
general, unlimited queues that the system can manage.  These operations should 
never block, if you can avoid it.

By separating the types of work, you give the system another opportunity to 
manage the load.  So, if one operation first does some I/O and then does 
computation, the system will be "fooled" by the CPU lull at the beginning into 
launching more operations and then hammered by the change to computation.  When 
the types of work are split, the I/O operations may be launched because there's 
free CPU capacity, but at least when the computation kicks in the system gets 
another chance to decide whether there are free resources to handle it.


> Also, is there a way to find out the number of cores on a machine so that I 
> can set that as a hard limit of number of operations on an NSOperationQueue?

-[NSProcessInfo activeProcessorCount]


> Here is an outline of how my code implements the daemon and the operations:
[snip]

It appears that your program is launching copies of itself to process 
individual files.  I suspect you're "bringing the whole system to a crawl" by a 
fork bomb.  Have you checked that your program is not infinitely-recursively 
launching subprocesses?

Also, why are you re-running your program in a subprocess, instead of just 
having your operation do the work directly?  (I suspect you do it that way in 
case processing of a particular file causes a crash.  You want to limit the 
crash to just the process handling that file.)

Have you considered letting launchd monitor the directories, launch your 
daemon, and deal with any crashes?

I'll also say that having NSOperations launch an NSTask and block waiting for 
it to exit is nearly a worst case scenario for NSOperationQueue.  It has a 
thread pool with idle threads, so it figures it can pull a new operation off 
the queue to start it with minimal new resources.  That operation not only 
monopolizes the thread, it does effectively nothing with it.  Instead, it 
launches a whole separate process, which is a significant use of new resources.

At least you could avoid the waste of the worker thread by launching the 
subprocess from the main thread.  Instead of blocking as you wait for it to 
exit, use the asynchronous notifications to trigger any followup work.  Of 
course, this approach doesn't integrate with NSOperationQueue, but you're 
effectively unde

Re: Three more questions

2010-11-14 Thread Dave DeLong
Broken link, sorry.  Use: http://regexkit.sourceforge.net/

Dave

On Nov 14, 2010, at 9:15 AM, Dave DeLong wrote:

> 1.  Use NSNumberFormatter
> 2.  Attach an NSNumberFormatter to the field
> 3.  Sounds like a great use of regular expressions.  Check out 
> http://regexkit.com
> 
> Cheers,
> 
> Dave
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: System resources and number of operations on an NSOperationQueue

2010-11-14 Thread James Bucanek
Antonio Nunes  wrote (Sunday, 
November 14, 2010 2:58 AM -):



The issue I am seeing is that the operation queue appears to indiscriminately
run operations as they are added to the queue, regardless of system resources,
thus bringing the whole system to a crawl. I thought, from reading the
documentation, that the queue would be intelligent about how many operations
it would have running at the same time, depending on system resources such as
number of cores and available memory. Since this doesn't seem to be the case,
I have to assume something is not quite right with my implementation.


NSOperationQueue uses Grand Central Dispatch, which will attempt 
to load-balance the number of running operations based on _CPU_ 
resources. However, that doesn't mean GCD will (or even can) 
automatically find the most efficient run schedule for your code.



My question: how can I ensure that no more operations are launched at any one
time than the system can handle?


-[NSOperationQueue setMaxConcurrentOperationCount:]


Also, is there a way to find out the number
of cores on a machine so that I can set that as a hard limit of number of
operations on an NSOperationQueue?


#include 
#include 

static unsigned int sNumberOfCPUs;

int name[2];
size_t len = sizeof(sNumberOfCPUs);
u_int value;
name[0] = CTL_HW;
name[1] = HW_NCPU;
if (sysctl(name,2,&value,&len,NULL,0)==0 && 
len==sizeof(sNumberOfCPUs) && value!=0)

{
sNumberOfCPUs = value;
[Logger log:kLogDebug format:@"detected %u CPUs",sNumberOfCPUs];
}
else
{
sNumberOfCPUs = 1;
[Logger log:kLogCurious message:@"Unable to determine the 
number of CPU cores; assuming 1"];

}
}

Personally, if your operation is mostly I/O bound, the best 
solution is to set maxConcurrentOperationCount to 1 and run the 
operations sequentially. The biggest problem in trying get 
better performance from I/O heavy processes is the HD trashing 
that occurs when you have more than one working simultaneously. 
This can easily mean that two operations will run slower than one.

--
James Bucanek

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Three more questions

2010-11-14 Thread Dave DeLong
1.  Use NSNumberFormatter
2.  Attach an NSNumberFormatter to the field
3.  Sounds like a great use of regular expressions.  Check out 
http://regexkit.com

Cheers,

Dave

On Nov 14, 2010, at 9:12 AM, William Squires wrote:

> 1) What's the best way to get an NSUInteger from an NSString that has a 
> string representation of a valid unsigned 32 bit integer (0..4,294,967,295). 
> There's an [NSString integerValue] and an [NSString longLongValue] (int64 
> anyone?), but not convenience methods on NSString that return an unsigned 
> integer value.
> 
> Here's my try: (given an NSString *s with the numerical representation)
> 
> ...
> long long i = [s longLongValue];
> // Get the lower 32 bits of i into l
> NSUInteger l = (NSUInteger)(i % 4294967296);
> 
> 'l' should - I hope - now have the NSUInteger value that 's' represents.
> 
> 2) Also, how can I make an NSTextField only allow valid unsigned 32 bit 
> integers to be typed in?
> 3) Finally, what's the simplest way to do a search and replace on an NSString 
> of the form @"x" (where "#" is replaced with valid characters in the 
> range '0'..'9') so that I can, in a for-loop from 0 to 9, replace the "x" 
> with a single digit? Something like:
> 
> NSString *oldNumber = ...; // Code to obtain the value of oldNumber, let's 
> say "x103"
> for (int i=0; i<10; ++i)
>  {
>  NSString *myNewNumber = [oldNumber replaceString:@"x" 
> withNewString:[NSString stringWithFormat:@"%u",_
>i]];
> 
>  // do something with myNewNumber...
>  }
> 
> myNewNumber should take on the values; "0103", "1103", "2103", ... "9103".
>  I'd like to make this a category on NSString for my number crunching project 
> I'm working on.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
> 
> This email sent to davedel...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Three more questions

2010-11-14 Thread William Squires
1) What's the best way to get an NSUInteger from an NSString that has  
a string representation of a valid unsigned 32 bit integer  
(0..4,294,967,295). There's an [NSString integerValue] and an  
[NSString longLongValue] (int64 anyone?), but not convenience methods  
on NSString that return an unsigned integer value.


Here's my try: (given an NSString *s with the numerical representation)

...
long long i = [s longLongValue];
// Get the lower 32 bits of i into l
NSUInteger l = (NSUInteger)(i % 4294967296);

'l' should - I hope - now have the NSUInteger value that 's' represents.

2) Also, how can I make an NSTextField only allow valid unsigned 32  
bit integers to be typed in?
3) Finally, what's the simplest way to do a search and replace on an  
NSString of the form @"x" (where "#" is replaced with valid  
characters in the range '0'..'9') so that I can, in a for-loop from 0  
to 9, replace the "x" with a single digit? Something like:


NSString *oldNumber = ...; // Code to obtain the value of oldNumber,  
let's say "x103"

for (int i=0; i<10; ++i)
  {
  NSString *myNewNumber = [oldNumber replaceString:@"x"  
withNewString:[NSString stringWithFormat:@"%u",_

i]];

  // do something with myNewNumber...
  }

myNewNumber should take on the values; "0103", "1103", "2103", ...  
"9103".
  I'd like to make this a category on NSString for my number  
crunching project I'm working on.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: More stoopid questions...

2010-11-14 Thread Matt Neuburg
On Sat, 13 Nov 2010 19:35:45 -0600, William Squires  said:
>1) Why is it, when you create a new Cocoa Application (or even some  
>iOS Applications) in Xcode, does it generate AppDelegate  
>(.h and .m) files, instead of calling them Controller (.h  
>and .m)? 

It's for your convenience. It used to be that the template *didn't* do this, 
and this created a bootstrapping problem for everyone who wrote an application, 
because there was no class in which to put your own code - especially your own 
code that was to run as the app launched. So the first thing every programmer 
did was create a class (MyClass), put an instance of it into the main nib (so 
that there would be a MyClass instance when the app launched and the nib was 
automatically loaded), and make it the application's delegate (so that it would 
receive applicationDidLaunch and some code would run).

We all did all those steps manually for years and years, on every single 
application we wrote. Finally Apple realized they could save us some steps and 
wrote it into the template. Since the purpose of the provided instance is to 
function as the app's delegate, Delegate appears in the name.

On iOS there is a further reason - there is an even more serious bootstrap 
problem. Without some object to run code and make the window key, no interface 
will appear. So on iOS not only do you get this app delegate instance, you get 
a line of code already in it that is called at launch (because this instance is 
the app's delegate, so it receives applicationDidLaunch) to make the window 
appear.

m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSUInteger = unsigned int?

2010-11-14 Thread Scott Ribe
On Nov 14, 2010, at 8:33 AM, William Squires wrote:

> In the "String Programming Guide" under "String Format Specifiers", it says 
> "%u or %U" for unsigned 32 bit integers. Is this what NSUInteger is typedef'd 
> to? Or do I need "%qu" instead?

NSUInteger is 32-bit for 32-bit architecture, 64-bit for 64-bit architecture.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSUInteger = unsigned int?

2010-11-14 Thread Dave DeLong
Further down in the document (In the "Platform Dependencies" section), it says 
you should use %ld or %lx for NSInteger and cast it to a long, and %lu or %lx 
for an NSUInteger and cast it to an unsigned long.

NSUInteger is typedef'd to either an unsigned int or an unsigned long, 
depending on your platform.

Cheers,

Dave

On Nov 14, 2010, at 8:33 AM, William Squires wrote:

> In the "String Programming Guide" under "String Format Specifiers", it says 
> "%u or %U" for unsigned 32 bit integers. Is this what NSUInteger is typedef'd 
> to? Or do I need "%qu" instead?
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
> 
> This email sent to davedel...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSUInteger = unsigned int?

2010-11-14 Thread William Squires
In the "String Programming Guide" under "String Format Specifiers",  
it says "%u or %U" for unsigned 32 bit integers. Is this what  
NSUInteger is typedef'd to? Or do I need "%qu" instead?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Catching errors with MPMoviePlayerController

2010-11-14 Thread Matt Neuburg
On Tue, 9 Nov 2010 08:12:54 +1100, Rogerio de Paula Assis  
said:
>Hi guys,
>
>Is there a way of catching exceptions (particularly for network errors
>/ no connection available) when using a MPMoviePlayerController?

I think the movie will finish and you can examine for 
MPMovieFinishReasonPlaybackError. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/matt/default.html#applescriptthings___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Default keyword selector type

2010-11-14 Thread Andreas Mayer

Am 13.11.2010 um 14:50 schrieb Michael Hall:

> Your links busted, 

The link is fine.


Andreas
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSController controllerEditor:didCommit:… exception

2010-11-14 Thread vincent habchi
Hi everybody,

this is a minor annoyance but I'm still puzzled about it.

When I launch my application, after -applicationWillFinishLaunching: completes, 
I get an exception started by -[NSController 
controllerEditor:didCommit:contextInfo:]. I cannot get a decent traceback to 
pinpoint what object is causing the exception, since it is ultimately raised 
from _NSFireDelayedPerform. It has somehow something to do with Core data, 
since ignoring it brings up the message "Cannot perform operation without a 
managed object context" (and no fatal error ensues).

While it is true the MOC is not initialized at this point, I don't see what 
could cause this message appear at such an early stage. Can it be linked 
somehow with the initialization of a static object embedded in the "MainMenu" 
NIB?

Thanks!
Vincent___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


System resources and number of operations on an NSOperationQueue

2010-11-14 Thread Antonio Nunes
I'm developing a daemon to run tasks as files get dropped into a folder. When a 
new file is detected, a new operation gets put onto the daemon's operation 
queue. The operation launches a task and waits for it to finish, then the 
operation exits.

The issue I am seeing is that the operation queue appears to indiscriminately 
run operations as they are added to the queue, regardless of system resources, 
thus bringing the whole system to a crawl. I thought, from reading the 
documentation, that the queue would be intelligent about how many operations it 
would have running at the same time, depending on system resources such as 
number of cores and available memory. Since this doesn't seem to be the case, I 
have to assume something is not quite right with my implementation.

My question: how can I ensure that no more operations are launched at any one 
time than the system can handle? Also, is there a way to find out the number of 
cores on a machine so that I can set that as a hard limit of number of 
operations on an NSOperationQueue?

The code is meant for 10.6.0 or higher and runs with garbage collection on.

Here is an outline of how my code implements the daemon and the operations:

All the daemon itself does, really, is to fire up a single  directory watcher, 
which is where all the action takes place. It then waits until it is signaled 
for termination, at which point it tears down the directory watcher and exits.

The crucial part of main() in the daemon:

--
directoryWatcher = [[ANDirectoryWatcher alloc] initWithOptionsBlaBlaBla...];

[directoryWatcher start];

while (1) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
}

// Should never get here
[directoryWatcher stop];
--

The directory watcher owns a single operation queue, to which it adds 
operations as new files arrive in the folder it watches:

--
-(void) handleNewFileFoundNotification:(NSNotification *)notification
{
NSString *sourcePath = [[notification userInfo] objectForKey:@"path"];

NSFileManager *localFileManager=[[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum = [localFileManager 
enumeratorAtPath:sourcePath];

NSString *file;
while (file = [dirEnum nextObject]) {
if ([[file pathExtension] isEqualToString: @"ext"]) {
NSString *filePath = [sourcePath 
stringByAppendingPathComponent:file];
// Process the document only if the path is new. 
Otherwise the document is already being processed.
if ( ! [self previouslyKnownPath:filePath] ) {
ANTaskLauncherOperation *operation = 
[[ANTaskLauncherOperation alloc] initWithSourceFileURL:[NSURL 
fileURLWithPath:filePath]


 ...other options...];
[self.operationInfo setValue:operation 
forKey:filePath];
[self.operationQueue addOperation:(NSOperation 
*)operation];
}
}
}   
}
--

The task launcher operation contains only three methods:

- An init method that is passed the required info and sets up essential 
instance variables based on the arguments.
- The following two methods:

--

- (void)completeOperation 
{
[self willChangeValueForKey:@"isFinished"];
[self willChangeValueForKey:@"isExecuting"];

self.executing = NO;
self.finished = YES;

[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];  
}


-(void)main 
{
fprintf(stdout, "%s Received file: \"%s\"\n", 
ANTaskLauncherCurrentTimeString(), 
self.sourceFileURL.path.lastPathComponent.UTF8String);
fflush(stdout);
NSTask *task = [[NSTask alloc] init];
NSMutableArray *args = [NSMutableArray array];

// Find path to binary
Dl_info info;
int errDlAddr = dladdr( (const void *)__func__, &info );
if(errDlAddr == 0) {
return;
}
char *exec_path = (char *)(info.dli_fname);

NSString *executablePath = [NSString stringWithCString:exec_path 
encoding:NSUTF8StringEncoding];
executablePath = [executablePath substringToIndex:executablePath.length 
- 1];

NSString *sourceFileName = self.sourceFileURL.lastPathComponent;
NSString *outputPath = [self.outputURL.path 
stringByAppendingPathComponent:sourceFileName];

...snip, adjusting outputPath some more...

/* set arguments */
[args addObject:@"-f"];
[args addObject:self.sourceFileURL.path];
...snip more arguments...

[task setLaunchPath:executablePath];
[task setArguments:args];

..