Re: NSMutableData capacity

2012-05-23 Thread Wade Tregaskis
> Can you not track the capacity yourself? Unless I'm missing something, if you > use > >+dataWithCapacity:some_capacity The docs note that this doesn't necessarily pre-allocate the given capacity. You can test that trivially by asking for a capacity of several gigabytes. In a nutshell, t

Re: architectures that prevent freezing

2012-05-11 Thread Wade Tregaskis
>> While playing with GPU programming, I had a lot of such freeze, and they >> never locked the CPU. I was always able to connect to my machine though SSH. Sometimes you can, sometimes you can't. It depends on exactly how things fail. > So a regular user process can permanently lock up the disp

Re: Instruments, how to fix leak in C Lib

2012-05-02 Thread Wade Tregaskis
> Bytes Used# LeaksSymbol Name > 84.81 KB 100.0%48PQgetResult > 84.81 KB 100.0%48 pqParseInput3 > 80.00 KB 94.3%40 pqResultAlloc > 80.00 KB 94.3%40 malloc > 4.00 KB 4.7%4 pqAddTuple > 4.00 KB

Re: Concealing an app from DTrace

2012-05-01 Thread Wade Tregaskis
> Is that the only way? Or is there something easier that would bypass the flag? There are several that I know of. But my question first, to you, is why? I can tell you now that you can't reliably defend against all approaches. What you can do is make things really awkward for yourself for de

Re: Minimal document-based app

2012-05-01 Thread Wade Tregaskis
> Unlike other graphical UI layout tools, Interface Builder is central to Cocoa > development, not simply a shortcut for newbies or a way to get started > quickly. Anyone who thinks developing without Interface Builder is a purer > path to understanding Cocoa has already missed the point. Actua

Re: WWDC

2012-04-25 Thread Wade Tregaskis
> I filed a bug report under "other" asking them to increase the numbers of > attendees at future WWDC. I thought this for a long time, but then came to the realisation that what's really valuable about WWDC just doesn't scale: access to Apple engineers. This wasn't always the case. The WWDC p

Re: WWDC

2012-04-25 Thread Wade Tregaskis
> I'd probably like to file one asking them to do *several* WWDCs around the > world – the cost to people in the bay area is already pretty high ($1.6k ish > per attendee), but to someone in the UK, the cost is more like $4k per > attendee. Plus of course doing several would kill the second sto

Re: Is there a list solely for ObjC/compiler language issues?

2012-03-27 Thread Wade Tregaskis
> Just curious... :) ObjC: objc-langu...@lists.apple.com (https://lists.apple.com/mailman/listinfo/objc-language) Clang: cfe-...@cs.uiuc.edu (http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Ple

Re: Can't delete file on device

2012-03-27 Thread Wade Tregaskis
> Okay, I made that change, but it seems blatantly incorrect to create an error > return if it is also going to return true. It only returns you something if it says it did, by indicating that an error occurred. Otherwise, the contents of the error parameter are undefined. There are definitely

Re: How to tell which thread is which in the debugger?

2012-03-22 Thread Wade Tregaskis
> I was hoping that the ‘name’ property of the NSThread would show up in the > debugger, since it does display names with some threads. But it doesn’t. (Why > not?) How can I set a name that will show up in the debugger — do I need to > use the pthreads API for that? You should try pthread_setn

Re: NSData, CFData maximum length question

2012-03-21 Thread Wade Tregaskis
> I'm not sure what [NSMutableData dataWithCapacity:0] does, but it's not a > simple call to CFDataCreateMutable(kCFAllocatorDefault, 0) which is why it > behaves differently as well. It probably ignores the specified capacity, for a start. NSMutableDictionary does for its equivalent method, a

Re: How to get Mac codesign certificate?

2012-03-17 Thread Wade Tregaskis
On 17/03/2012, at 7:54 AM, Marco Tabini wrote: >> Can you not just use a free provider, like http://www.startssl.com/? > > I'm not an expert, but I think the free cert they provide cannot be used for > code signing. FWIW they can; they'd be pretty useless otherwise. Many of them are marked, ho

Re: How to get Mac codesign certificate?

2012-03-17 Thread Wade Tregaskis
>> But I want to codesign my OS X apps. >> So how do I get the necessary certificate? > > You need to buy it from a certificate authority, like Thawte or Verisign (or > one of the myriad resellers) and they will all be happy to sell you one at > prices that range from around $80 to around $500/y

Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-15 Thread Wade Tregaskis
> While all these points are very good, I disagree with the conclusion > because I believe in the wisdom: Keep simple things simple. An argument for doing this in the frameworks is that it is then simpler to do this. No need for every developer to write the same boiler plate every time. And if

Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-14 Thread Wade Tregaskis
> I don't like the idea of a multithreaded aproach by default, because as a > general rule, you > should not make your application multithreaded unless you have a good > reason. a) The reality is that Cocoa already exposes you to a lot of concurrency and asynchronisity, and is only going to do m

Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-14 Thread Wade Tregaskis
> The problem of course, is that in order to allow that, the framework itself > has to be locking things all over the place, regardless of whether or not an > app is actually accessing any particular data from multiple threads, because > now the framework has to assume that might happen. Yes an

Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-14 Thread Wade Tregaskis
>> Likewise even event handling is often effectively multi-threaded, because >> you dispatch from the main thread to a variety of tasks, queues or worker >> threads. > > But then you are receiving the events on the main thread? What do you > mean? If you receive events on the main thread, and d

Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-14 Thread Wade Tregaskis
> Threads themselves are very useful; multiple threads taking user input and > updating the display to the user are not really useful, and the request for > them more often than not betrays a lack of understanding of threading. So you think it'd be great it every GUI app shared the same serial q

Re: The current preferred method for fetching HTTP URLs for IOS

2012-03-09 Thread Wade Tregaskis
> FWIW, my view is that it depends on what your requirements are. For a simple > request, you can go with an [NSString stringWithContentsOfURL] wrapped in a > call to dispatch_async to avoid blocking the main thread. But keep in mind that threads are not free and there are a finite number avai

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Wade Tregaskis
> I’m not sure I’d want that either, though. If the original string was a > 200-page dissertation and you took a one-word substring from it, it doesn’t > seem reasonable to keep the whole 200-page dissertation all in RAM just to > keep the one-word substring around. But that's a very old probl

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Wade Tregaskis
Perhaps the only 'correct' solution to this problem is to fall back to the CFString level, where you can pass a custom CFAllocator to e.g. CFStringCreateWithBytesNoCopy(). That way the lifetime is effectively managed by the CFString, so it should behave correctly in all cases. 'course, the imp

Re: Xcode - An Apple Embarrassment

2012-02-29 Thread Wade Tregaskis
> *No*. I've said it before (right here) and I'll say it again; this is *not* > jumping to the documentation, and it is *not* doing what Xcode 3 did. It > switches to the documentation window and it enters the double-clicked word > into the search field, and it does the search, but it doesn'

Re: [Obj-C] if (self) vs. if (self != nil)

2012-02-25 Thread Wade Tregaskis
>if(nil != (self = [super init])) > > Myself I find it elegantly brief and imminently readable. I don't mind it, but to me it begs the question of what it offers over: self = [super init]; if (self) { My rationale is, generally you avoid assignments within conditionals becau

Re: [Obj-C] if (self) vs. if (self != nil)

2012-02-24 Thread Wade Tregaskis
> if(self == nil)... > if(self = nil)... > if(nil == self)... > if(nil = self)... > > The 1st & 3rd are the correct conditions, the 2nd & 4th are typos. But the > 2nd compiles and gives incorrect behavior, while the 4th fails to compile. > > Of course if(self) is not subject to that kind of typo

Re: [Obj-C] if (self) vs. if (self != nil)

2012-02-24 Thread Wade Tregaskis
> self = [super init]; > if (self) > { > } > return self; > > self = [super init]; > if (self != nil) > { > } > return self; > > The Xcode samples promote the first variant, but I'm wondering if the > second one is more correct? No. The more common convention in (Apple's) ObjC is to use implici

Re: How to get the dispatch queue for the current thread's runloop?

2012-01-28 Thread Wade Tregaskis
> Where do they say that? That's surely wrong. The man page says that in that > case it returns the default-priority global [serial] queue. Nevermind, I'm not paying enough attention. I figured you'd have to return a serial queue, so my brain conveniently ignored the fact that the global defa

Re: How to get the dispatch queue for the current thread's runloop?

2012-01-27 Thread Wade Tregaskis
> It looks like I should just call dispatch_async, but I'm unsure which > dispatch queue to use. dispatch_get_main_queue only works for the main > thread. Can I use dispatch_get_current_queue? I'm unsure of what this does > when called on a background thread. The API docs say "If the call is mad

Re: Is slowing down bindings updates possible?

2012-01-12 Thread Wade Tregaskis
> The result of this is that the UI updates really frequently and the > estimated time to complete and the download rate jump around a lot. I > would love it if I could tell cocoa to only update the UI once per > second instead of immediately when the property key changes. I don't believe there is

Re: checking if directory is writable

2012-01-12 Thread Wade Tregaskis
> I was of the understanding that Apple's recommendation was just to try the > operation you wanted to perform, and handle the error if there is one. This > is taken from the NSFileManager header, directly above the isWriteableAtPath: > declaration: > > "The following methods are of limited uti

Re: Crash and dispatch queue

2011-11-17 Thread Wade Tregaskis
> [myObject saveDataToFile]; What does this method actually do? From the sounds of it your analysis has determined that running this from a thread other than the main one is problematic. If so, first thing is to figure out why the thread matters at all. If you can't make it thread safe, then

Re: Allocating too much memory kills my App rather than returning NULL

2011-11-08 Thread Wade Tregaskis
> Simple as that, eh? Being able to gracefully handle all out of memory > situations to me seems as "simple" as being required to treat every single > method / function call as potentially raising an exception, and requiring the > developer to add handlers + cleanup code. No existing code (OS or

Re: Allocating too much memory kills my App rather than returning NULL

2011-11-08 Thread Wade Tregaskis
>> Before I started writing iOS code I did embedded systems development >> and Mac OS X device drivers. In both of those environments, Failure >> Is Not An Option. While you can certainly run out of memory or >> encounter other errors, one just has to back out gracefully. > > This turns out not

Re: Allocating too much memory kills my App rather than returning NULL

2011-11-07 Thread Wade Tregaskis
> Also I'm pretty sure the iOS memory allocator is multithreaded, and > that Apple's code would be good about checking for runtime failures. > If it does not, then that is a bug in the iOS. That's my opinion too, but there are plenty of people within Apple who are vehemently against it. So while

Re: Allocating too much memory kills my App rather than returning NULL

2011-11-07 Thread Wade Tregaskis
>> If calloc() ever returns NULL while attempting to allocate the new >> grid, I back out all of the successful allocations by passing each >> array pointer to free(). Then I display an alert to the user to >> advise them that there is not enough memory for their desired grid >> size, and suggest

Re: Why does ARC retain method arguments even with full optimization?

2011-11-05 Thread Wade Tregaskis
>> Note that (so far as Mac OS X is concerned - I don't know about iOS) this >> only happens with the 64-bit runtime on Intel, on Lion. Previous runtimes >> don't even have this optimisation, and there's somewhat surprisingly no >> 32-bit implementation of the critical callerAcceptsFastAutorele

Re: Why does ARC retain method arguments even with full optimization?

2011-11-05 Thread Wade Tregaskis
> The way I understand it with ARC, though, is that it can peek at the stack to > see what will happen to a pointer after it’s returned, and cut out some of > the unnecessary message sends, so while it’s actually generating something > like this: > > - (Foo *)foo { > return objc_retainAut

Re: ARC + return of autoreleased CFType

2011-10-19 Thread Wade Tregaskis
> Following Cocoa convention you'd want to cast it to what and autorelease it? > CGColorRef isn't toll-free bridged with anything. If you have been casting it > to id and autoreleasing it you might have gotten away with that before but I > don't think it's documented anywhere you can do that wit

Re: Retain/Release and Properties clarification

2011-10-07 Thread Wade Tregaskis
> In addition to what Kyle replied, I'd just like to point out that prefixing > your *methods* with an underscore is a very bad idea, since Apple does > reserve such names and a conflict will bite you at runtime possibly affecting > the binary compatibility of your app. I would argue that under

Re: Optimizing a loop

2011-08-10 Thread Wade Tregaskis
> //This takes about 6 seconds each search for song* >for (id key in songsDictionary) { >NSString *thisSong = key; >int suppliedCount = [stringValue length]; >int keyCount = [thisSong length]; >//Fuzzy matching

Re: Opening a file read-only?

2011-08-10 Thread Wade Tregaskis
> Try running fs_usage while your app is running, and you’ll be able to see > what files it opens and in which modes. > (Or there’s probably an Instrument for that now?) There's half a dozen related to file I/O, which unfortunately makes it very awkward to use for even simple tasks like this. Y

Re: blocks and retaining CoreFoundation objects

2011-08-10 Thread Wade Tregaskis
>> The ARC specification defines a "retainable pointer" as including those >> pointers that have the __attribute__((NSObject)) decoration, so this should >> behave as expected under ARC. >> > > I am curious, though, in that CG

Re: CFMutableDictionary Capacity

2011-08-09 Thread Wade Tregaskis
>>> According the doc, the parameter "capacity" in function >>> CFDictionaryCreateMutable() sets the *maximum number* of key-value pairs >>> which can be inserted into the container. That is, it's not an *initial* >>> capacity. >> >> I think that was a mistake in the docs. The comment in CFDict

Re: Does anyone else dislike Xcode 4?

2011-08-05 Thread Wade Tregaskis
> Well, one thing I just discovered in Xcode 4 and is already annoying me > highly is that the app somehow uses CoreAnimation so that now, even though > I'm running on battery, it forces the OS to use the Radeon video chipset > instead of the integrated Intel's one, which is less power hungry. T

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?

2011-08-05 Thread Wade Tregaskis
> I'm not sure really what the argument here is. What both of you seem to be > asserting is "you could construct any object from a file… that file might be > maliciously structured to construct objects that behave in evil ways". This > is true, but I'm not sure I see how this differs for *any*

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?

2011-08-02 Thread Wade Tregaskis
>> That'll need to be updated. If you look at the @autoreleasepool section of >> the ARC documentation, it specifically states that crossing out of one via >> an exception will not drain the pool. There doesn't appear to be any way, >> even through compiler flags, to change this. > > If an au

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?

2011-08-01 Thread Wade Tregaskis
>> Any code that throws exceptions will probably leak a few objects, since >> according to the ARC design doc the ABI requires not draining autorelease >> pools while unwinding the stack. > > Are you sure (or does ARC work differently)? > >

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?

2011-08-01 Thread Wade Tregaskis
>>> Granted that NSKeyedUnarchiver might have left some memory leaks or >>> partially uninitialized objects somewhere, but unarchiving an invalid >>> object should happen rarely if at all... and ordinarily my own code should >>> never get pointers to such objects, anyway. >> >> Indeed there may

Re: Filter an array

2011-07-29 Thread Wade Tregaskis
> Further to earlier answers, bear in mind you've got no guarantee that file > extensions are correct, or even exist. Plus of course, you might have both > .jpg and .jpeg. You might well be better iterating through, finding the UTI > of each file, and working from that. Oooh, that's kind of emb

Re: Zeroing out instance variables

2010-04-16 Thread Wade Tregaskis
>> 3. bzero(individual + individualIvarsOffset, individualIvarsSize); > > This should cast "individual" to void* before doing the pointer arithmetic, > of course. And of course by "void*" you meant "uint8_t*". Pointer arithmetic is undefined on voids... it happens to be supported by gcc & cla

Re: Analyzer Questions

2010-02-02 Thread Wade Tregaskis
>> Thanks, changing several methods to use the 'new..." naming standard did >> the trick. Using create as suggested by Wade didn't fix the problem, which >> explains why another method (createBitmapContext) was showing similar >> behavior. > > Create only works with functions (CF convention).

Re: Analyzer Questions

2010-02-02 Thread Wade Tregaskis
> - (CGPDFDocumentRef)getPDFDocumentRef:(const char *)filename { > CGPDFDocumentRefdocument; > >snip... > > document = CGPDFDocumentCreateWithURL(url); > return document; > } The CF convention is that functions and methods that return a literal reference t

Re: What is the life of the c string returned by NSString's UTF8String method?

2009-09-18 Thread Wade Tregaskis
Or to avoid a copy and raw memory management, you can also query directly an NSData from the string using -[NSString dataUsingEncoding:NSUTF8StringEncoding] and then use -[NSData bytes] as the returned value for this method is guarantee to have the same life as the NSData object. Though o

Re: debugging strategy

2009-09-16 Thread Wade Tregaskis
Here is the situation. We have a large application that has been in the field for several years now. We are adding new feature for our next release, and we are testing the new builds against Snow Leopard as well as earlier versions of OS X. Under Snow Leopard, some existing functionalit

Re: literal strings - who do they belong to?

2009-07-13 Thread Wade Tregaskis
id obj = [dict objectForKey:@"whatever"]; [dict release]; NSLog( @"this will crash %@", id ); And if you extrapolate this example further to the case where [dict release] is called on another thread, you're in a real pickle. Ideally, objectForKey: would retain]autorelease]. This multithre

Re: literal strings - who do they belong to?

2009-07-13 Thread Wade Tregaskis
There's also a high cost, in CPU cycles and memory, to retain/ [auto]release in such an excessively defensive way. And have fun using Object Alloc to find real problems once you've added these superfluous retain/release/autoreleases to every return value in your entire program. But wouldn

Re: literal strings - who do they belong to?

2009-07-13 Thread Wade Tregaskis
{ NSData *data = [[NSData alloc] initWithBytes:foo length:bar]; const char *bytes = [data bytes]; [data release]; CrashByDoingSomethingWithBytes(bytes); } Why should this sort of thing be expected to work, just because the property in question happens to be an object? A facetiou

Re: literal strings - who do they belong to?

2009-07-12 Thread Wade Tregaskis
I know you guys probably know this, but to be technically accurate, there is no guarantee the return value of stringByAppendingString returns an autoreleased string. While your point is true, it's not actually a rebuttal - you can assume objects returned from such methods are autoreleased,

Re: Profiling a drag and drop operation

2009-06-06 Thread Wade Tregaskis
I don't know how well I understand the output I got from it. I found an area of my code , shark said was taking up about 4.8%, which was about the third highest entry in the results. Despite making that change the application, doesn't seem to load the file any faster. Additional Shark pr

Re: End Of Method Releasing Order?

2009-06-01 Thread Wade Tregaskis
does it matter which order objects are released at the end of a method? example: -=-=-=-=- - (void)applicationWillTerminate:(NSNotification *)notification { FourLines *fourLines = [[FourLines alloc] init]; fourLines.field1 = field1.text; fourLines.field2 = field2

Re: CF autorelease?

2009-04-23 Thread Wade Tregaskis
Another caveat with cleanup is that it is not guaranteed to be called. For this audience, the most likely way this will bite you is when the new zero cost objective-c exceptions aren't available (i386, ppc) and an exception is thrown. If zero cost objective-c exceptions are available, the

Re: CF autorelease?

2009-04-23 Thread Wade Tregaskis
Something I've been using as of late to make CF a little more bearable is the cleanup attribute offered by gcc, e.g.: static inline void _autoreleaseCFArray(CFArrayRef *array) { if (NULL != *array) { CFRelease(*array); } } #define CFAutoreleasedArrayRef __att

Re: Accuracy of timers?

2009-04-22 Thread Wade Tregaskis
As others have noted, NSTimers are bound by the runloops they operate in. Though you can always spawn a dedicated thread, create a run loop, add your timer, and then go; since nothing else is in the runloop, the latency should be quite low. I'd try that first, and see if it meets your nee

Re: Performance problem with GC enabled

2009-03-14 Thread Wade Tregaskis
Ah, right, sorry. I'm not saying the existing API would permit such a change, more's the pity. All I'm saying (and I doubt that saying this has any value) is that it could, and in my opinion should, have been done that way in the first place. It's very tempting to try to enforce this in a

Re: Convert unicode string into ascii

2008-08-28 Thread Wade Tregaskis
is a way to convert an unicode string into a simple a-z>0-9 string and replace the other wierd chars into a "." (full stop)? im doing a small hex reader, so maybe this could help you. CFDataRef CFStringCreateExternalRepresentation ( CFAllocatorRef alloc, CFStringRef theString, CFString

Re: Deep Recursion

2008-08-27 Thread Wade Tregaskis
Is there some way (environment variable?) to limit the stack size to something smaller, so that the exception (probably from stack corruption) would show off earlier? http://developer.apple.com/qa/qa2005/qa1419.html - Customizing Process Stack Size You can set limits/ulimits, define it at

Re: what is radar:// supposed to open?

2008-08-16 Thread Wade Tregaskis
sorry not totally cocoa but this is the 2nd or 3rd time I've seen 'radar://' , clicked it, and I get an instant crash of something called mobilesafari. What's supposed to open radar:// links? I tried safari but it just does the same thing. I'd actually like to be able to track some of these

Re: Using performSelector: on super

2008-08-06 Thread Wade Tregaskis
The try/catch setup is well optimized and introduces very little overhead. So in the nominal case, where there is no exception, there's almost no overhead at all. Even if an exception was thrown, NSException is fairly lightweight. This is not particularly accurate. There, I'll beg to diff

Re: Calling autorelease on CFAllocated objects?

2008-07-09 Thread Wade Tregaskis
http://www.cocoabuilder.com/archive/message/cocoa/2008/7/5/212046 I wish this were better documented; the Search Kit docs show autorelease being sent to an SKDocumentRef, also, and that's always made me nervous (I think I actually sent feedback on that one a long time ago). I do apologise

Re: Calling autorelease on CFAllocated objects?

2008-07-09 Thread Wade Tregaskis
I have a memory management question. I was looking at the QCTV example on from the quicktime site. It has some code that does the following: ICMCompressionSessionOptionsRef options; .. Do some work .. return (ICMCompressionSessionOptionsRef)[(id)options autorelease]; Can you do this with

Re: Xcode eats 100% CPU and more while typing

2008-05-13 Thread Wade Tregaskis
For more information you can read up on Time Profiling in the Shark user manual, and specifically Windowed Time Facility (WTF). Somewhere along the way someone ate my links. Thanks a lot, anonymous gremlin. :) Time Profiling: http://developer.apple.com/documentation/DeveloperTools/Conceptu

Re: Xcode eats 100% CPU and more while typing

2008-05-13 Thread Wade Tregaskis
In any case, I'll definitely be filing a radar next time it happens. Problem is, it's next to impossible get a repro the problem given the number of variables (environment, SCM, project, the file itself, and whatever UI actions/history that led up to that point), so we come back to the str

Re: Anyone used btlsocket framework?

2008-05-10 Thread Wade Tregaskis
btlsocket is a new open-source Cocoa framework that provides a high-level API for TCP and UDP sockets. On first glance it looks quite nice, definitely a step up compared to using NSStreams directly (a la the CocoaEcho sample.) But it's so new that I can

Re: Tight loop processing

2008-04-10 Thread Wade Tregaskis
Threads are almost always the right way to do what the OP wants. The problem as was presented is that there's some work to do, which happens to be dividable into N segments. There were no bounds placed on how long it takes to run any individual segment. And even if there were, they'd pro

Re: Charting API? (Chris Schmitt)

2008-02-27 Thread Wade Tregaskis
Apple has the makings of such a framework already - its called GraphKit. If you want GraphKit to become available as a supported Cocoa framework PLEASE enter an enhancement bug - you can reference the same bug my request was dupped to: 3320659 [its low number tells you its a long standing