iDevGames Forums
Parsing from a string to something faster? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Parsing from a string to something faster? (/thread-876.html)



Parsing from a string to something faster? - Madrayken - Aug 10, 2009 12:33 PM

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?


Parsing from a string to something faster? - ThemsAllTook - Aug 10, 2009 12:52 PM

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?


Parsing from a string to something faster? - Madrayken - Aug 10, 2009 01:18 PM

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


Parsing from a string to something faster? - smasher - Aug 10, 2009 03:32 PM

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!