Re: Reading in dictionary from txt file: options for speed
Re: Reading in dictionary from txt file: options for speed
- Subject: Re: Reading in dictionary from txt file: options for speed
- From: Greg Guerin <email@hidden>
- Date: Thu, 16 Apr 2009 17:55:09 -0700
Miles wrote:
const char *fileBytes = [stringFileContents bytes];
char *ptr = strstr(fileBytes, cString);
Are you certain the bytes returned by [stringFileContents bytes] null-
terminated? How was that data initialized? If it's reading from a
file, is there guaranteed to be a null-terminator in the file? What
happens if there isn't? Suppose the file gets edited and loses any
overt null-terminator you have now, what will your program do?
Was the original suggestion to use strstr(), or was there a similar
function with a length?
You also need to think about case-sensitivity, because searching for
"joy", "Joy", "joY", or "JOY" might be different depending on where
the search-term is coming from, and what letter-case means (or
doesn't mean) in context.
And what is the context? I don't think you ever said what you were
trying to accomplish with this dictionary and searching in it.
And since you have the words "options for speed" in the Subject, it's
possible that strstr()'s linear search could be a speed problem. Or
it's possible that linear search is fine (for worst-case, test it
with a word that you know isn't anywhere in the dictionary). And
that goes back to the "What are you trying to accomplish?" question,
now that the "how to" has been more or less answered, at least for
one case.
-- GG
_______________________________________________
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