Re: reading (parsing) CSV (or Excel) data
Re: reading (parsing) CSV (or Excel) data
- Subject: Re: reading (parsing) CSV (or Excel) data
- From: Colin Howarth <email@hidden>
- Date: Fri, 2 Oct 2009 22:03:23 +0200
Yes, thanks Mike (and all others). My particular table is only around
100 x 100 cells, so Drew's code is fine.
Regarding the efficiency points raised in these posts, perhaps
Stephen's pointer
libcsv is a potential option. http://sourceforge.net/projects/
libcsv/
is a good idea. CSV isn't *that* hard to parse, once you know about
quotes and NLs inside cells. Maybe a Cocoa wrapper enabling one to
*use* libcsv in a Cocoa-ish way would be a good idea. You don't really
need to create an instance with
[MyLetter letterWithLetter: (chr) aLetter encodedUsingEncoding:
(NSStringEncoding *) someEncoding possiblyUsingSomeFont: (NSFont *)
aFont]
or
[MyLetter createALetterByReadingFromString:(NSString *)
theStringImLookingAt whichMightBeEncodedUsingEncoding:(NSEncoding *)
anEncoding
butIfItIsntEncodedOrIfICantFigureOutTheEncodingLookAtThisError:
(NSError ***) error andAssignANiceFont: (NSFont *)font
andOfCourseASize: (NSPointSize *) makeAPointSizeNumberUsingANumber
( pointSize)]
for each letter in the file and then
[parser lookAtTheLetterIJustRead: (MyLetter *) theLetter
andDecideIfItBelongsToTheMutableClassOfSeparatorCharacters:
(NSMutableArray *) ...
...
:-) (sorry)
I mean, one doesn't *have to* implement the parser in Objective-C,
does one?
Maybe I'll have a go (I need the practice) when I've Finished (TM) my
current project...
-- colin
On 2 Oct, 2009, at 15:49, Adam R. Maxwell wrote:
On Oct 2, 2009, at 6:10 AM, I. Savant wrote:
On Oct 2, 2009, at 7:42 AM, Mike Abdullah wrote:
While using this code in an experimental project I found the app
was routinely using 500+ MB of RAM. When measured with Instruments
I realised that every time you use a character set for string
scanning, Foundation internally copies it, presumably to ensure it
has an immutable object to work with. As a result, potentially
thousands of copies are being created, resulting in either:
A) Outrunning the garbage collector
B) Spending far more time allocating and deallocating character
sets than doing the actual scanning
Easiest solution is just to make a single copy yourself early on.
Also the docs for NSMutableCharacterSet do point out that it's
inefficient but don't really offer any detail.
Very good to know, thanks, Mike. You might want to post a comment
on the macresearch.org page so Drew can adjust the example.
I've also run into major performance problems with -[NSScanner
scanCharactersFromSet:], which creates an inverted, autoreleased
character set each time it's called. This blows up autorelease
pools (and inverting character sets isn't fast either). Filed as rdar://problem/4652388.
My workaround for this is generally to invert the set myself and use
scanUpToCharactersFromSet:, but that could be hurting this example
as well.
Do you happen to remember what percentage of difference you were
able to achieve? It's fine if not - it's not too difficult to set
up a test. :-)
In my case I was running out of address space and crashing, which is
pretty easy to detect :).
_______________________________________________
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
_______________________________________________
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