Parsing from a string to something faster?

Member
Posts: 110
Joined: 2009.07
Post: #1
I have a nice little class that loads in all .pngs files named 'arbitrary_name_<n>.png' in my art directory (where <n> is a value).

It stores them in a dictionary so that I can do things like this:

Code:
- (void) drawSpriteToBuffer: (GLfloat *) buffer WithSpriteName: (NSString *) graphic_name;

[self drawSpriteToBuffer: buffer WithSpriteName: @"mr_flibble"];

All is well and good... ish.

But this dictionary lookup seems a bit... well... high level and expensive. I'm loathe to replicate data if I can avoid it, so I don't want to hand-create a bunch of enums which map one-to-one against my files.

I've been considering using my graphical processing script (in python) to spit out a nice enums.h file in C format.

Anyone else doing anything cleverer?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Dictionary lookups ought to be pretty quick. Have you profiled with Shark and had it show you that this is a hot spot in your code?
Quote this message in a reply
Member
Posts: 110
Joined: 2009.07
Post: #3
ThemsAllTook Wrote:Dictionary lookups ought to be pretty quick. Have you profiled with Shark and had it show you that this is a hot spot in your code?

Not sharked this yet; the root of all this is something I chose not to explain as I thought it might make my initial question far too confusing. It seems like getting a text file to result in code-readable information would be quite useful. Perhaps I'm getting ahead of myself and optimising too early... it's been known to happen. LOL
Quote this message in a reply
Member
Posts: 27
Joined: 2008.12
Post: #4
Madrayken Wrote:Not sharked this yet; the root of all this is something I chose not to explain as I thought it might make my initial question far too confusing. It seems like getting a text file to result in code-readable information would be quite useful. Perhaps I'm getting ahead of myself and optimising too early... it's been known to happen. LOL

Definitely profile it before you worry about how fast a dictionary lookup is - you may be surprised. And don't worry about optimizing at all until all major features are in place - there is no point at all in hand-tightening code that you may throw away in a month or a week. That's time wasted!

-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under $1k
-- Twitter: xsmasher
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  formatting value in a string sefiroths 3 4,038 Dec 12, 2011 02:41 AM
Last Post: sefiroths
  Getting a value from a String Megamac04 5 3,831 Jan 31, 2010 04:23 PM
Last Post: smasher
  Is -fconstant-string-class broken under the XCode/Next runtime Justin Brimm 17 7,695 Jun 12, 2008 01:04 PM
Last Post: Justin Brimm
  string to interger comparison? dareuhl 8 4,399 May 22, 2008 05:44 PM
Last Post: OneSadCookie
  OH GAWD! Text parsing in cocoa?!?!? hypnotx 6 4,413 Jul 5, 2007 12:57 PM
Last Post: SethWillits