• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
dave j

String handling in C

32 posts in this topic

Since when were string operations a major performance bottleneck in games?

 

Unless one is doing a lot of text-parsing at runtime (in which case it may be an appropriate topic for a new post in this subforum...)

2

Share this post


Link to post
Share on other sites

You're not supposed to do that, at worst you're supposed to do all text parsing at load time and leaving the run time parsing only for showing stuff on screen. Pretty much everything a game is bound to need can be converted to integers and such.

 

Though I do know of an engine that requires you to fetch all resources through strings. And you need to do this every time you pretend to use a resource, and consider about every object in the map is bound to use at least one or two resources of those every frame... (a similar issue happens if you use string indices instead of integer indices for arrays)

1

Share this post


Link to post
Share on other sites

Though I do know of an engine that requires you to fetch all resources through strings. And you need to do this every time you pretend to use a resource, and consider about every object in the map is bound to use at least one or two resources of those every frame... (a similar issue happens if you use string indices instead of integer indices for arrays)

eh?, that sounds really broken, can't you hold an pointer to the resource?, or does the resource manager control how the resource is also used(which still sounds broken to me)?

0

Share this post


Link to post
Share on other sites

gcc looks at the format string for printf & co and gives a warning I think. It has to be built in to the compiler (or via metadata related to a function declaration) since using variable length argument lists removes all checking to do with type and number of arguments...

 

Clang also does this, plus, it also checks that the format string is correct with respect to argument types. Really handy!

 

Also LLVM (used with XCode for iOS and OSX). Indeed really handy!

0

Share this post


Link to post
Share on other sites

Though I do know of an engine that requires you to fetch all resources through strings. And you need to do this every time you pretend to use a resource, and consider about every object in the map is bound to use at least one or two resources of those every frame... (a similar issue happens if you use string indices instead of integer indices for arrays)

eh?, that sounds really broken, can't you hold an pointer to the resource?, or does the resource manager control how the resource is also used(which still sounds broken to me)?

Custom scripting language >.>' But even then, it could have had a retrieve ID function or something, but nope, the string is the ID, so e.g. if you want to play a sound effect you need to pass the name of the sound effect, if you want to switch to a specific sprite you need to pass the name of the sprite, etc. I suppose it's sorta mitigated by hashing, but integers/pointers/whatever as IDs would still have been a ton faster compared to strings.

 

As far as I know that engine was never pushed to its limits yet, so maybe that's why nobody got bothered by it in the first place. I presume some time in the future that will eventually happen, though. The only upside of its approach is that it may be slightly easier for beginners to get running.

0

Share this post


Link to post
Share on other sites


Since when were string operations a major performance bottleneck in games?

 
Unless one is doing a lot of text-parsing at runtime (in which case it may be an appropriate topic for a new post in this subforum...)


or, if major pieces of engine infrastructure are based on strings...

(good or not, it can sometimes end up happening this way...).


this is basically things like using strings to identify things, and using constructs like:
if(!strcmp(str, "_foo_t"))
{
...
}else if(!strcmp(str, "_bar_t"))
{
...
}else if ...

which, if not careful, can end up eating a lot of time, and then one is left to try to figure out why "strcmp()" has jumped to the top of the list in the profiler (*1).

but, at least, one can intern the strings, and in these cases using '==' and '!=' on the pointers can lead to slightly faster string comparisons (but has other drawbacks, like often the need to cache literals in variables, or resort to ugly hacks). (if both are already interned, it is basically just the cost of the pointer comparison).

some of this may result because strings are self-describing and easier to use as decentralized unique IDs than integers, and generally also easier to work with than GUIDs.

ADD: another past trick is to basically use a hash-table to quickly map a string to an integer based index (the position of the string within an array of strings), and then use this index with a "switch()", which can at least generally be faster than a long strcmp() based if/else chain, and generally comparing favorably to a big nested switch (less awful looking, and also faster in many cases).


*1: like, one time in my renderer (earlier on), I ended up profiling things, and observing that "strcmp()" was at the top of the profiler list. I then looked into it and found that this was because an inner loop (related to querying objects) was falling back to one of these strcmp() if/else chains (dispatching to the logic for each specific model type) for each iteration of the loop (which at the time was also a linear search over every object in the world).

things have improved at least slightly since then (much of this logic has since been moved to vtables, ...).

(actually, much of the engine runs on top of a dynamic type-system, itself based mostly around string-based type-ID names, which are used for pretty much every heap-allocated object in the engine, ...).

nevermind cases where strings and while-loops directly drive program logic in a few places (typically "type signature strings", ...), ...

and also the frequent use of strings to identify things like entity field-names, the contents of a database-like structure, file paths, ...


also if one builds parts of their logic on top of working with DOM-like XML trees or similar (like, using XML trees as a data-structure for representing other data), this can also involve using a lot of strings. historically, some code had also worked largely by walking XML trees and dispatching to logic, but most of this code went away as the performance was often a bit lacking (the only major examples left have since largely been relegated to offline tools).

a lot of other code uses walking Lisp-like lists instead, which are a bit faster. (lists are basically a tree-structure composed of linked-lists of "cons-cells", with each list holding a string identifying its contents, ...).


so, depending on the code, strings can be a big deal.

though, the it makes sense to avoid a lot of stuff like this in performance-critical areas or as part of the main execution path. Edited by cr88192
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0