• 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
Infinisearch

C++ multiple files and low-level effects

5 posts in this topic

*Note the following is for the purpose of accurate knowledge, no responses of why do you care, or it doesn't really matter necessary.


I was thinking about the compilation process and ASM the other day and came up with the following question: Are there any "adverse" low-level effects to multi-source file compilation in C++? The reason I ask is as follows, object code (prelinker) is in Machine Language right? So the addressing mode to all branches and jumps have already been 'baked in' so if every source file is an independent translation unit doesn't the branches or jumps (between each translation unit) have to be a full pointer instead of smaller (PC relative) immediate data? If so does/can the compiler optimization mode make a difference? It doesn't seem possible but I thought I'd ask.

In summary I've seen source where every class has its own cpp and header file, and basically wondered if the executables made with this extreme were more 'bloated' for it?


Thank You in advance for any insight into the subject matter.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1342869349' post='4961632']
A bigger deal is that any optimisations done by the compiler are restricted to that translation unit (e.g. the compiler can't inline a function that's implemented in a different translation unit). However, modern compilers support Link Time Code Generation and Whole Program Optimization, which allows the linking step to act like an optimising compiler and re-write code after/during linking.
[/quote]
Assuming you don't have the latter what source code solutions are available to allow for inlining? On a related note, I once read somewhere that if you inline (put implementation in class definition) the compiler will inline the object code, is this true? (I didn't believe it)
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1342869349' post='4961632']
Branches can be re-written/translated/moved/patched, as long as a 'baked' section of code has some kind of manifest/reflection data with it, describing the locations of pointer/offset values.
[/quote]
Just to be sure you are saying a set of instructions (2 or 3) to execute a branch can be rewritten to a single branch instruction (or moreover a branch instruction of size X can be changed to a branch instruction of size Y) and then all the branch targets after said branch will be updated and then all branches in other translation units then get updated with the new branch targets. And this goes round and round till everything 'settles into place'? Wow if so i'm impressed, I never knew linkers' were that complicated.
0

Share this post


Link to post
Share on other sites
[quote name='Infinisearch' timestamp='1342901345' post='4961755']
On a related note, I once read somewhere that if you inline (put implementation in class definition) the compiler will inline the object code, is this true? (I didn't believe it)
[/quote]

Maybe.

You should treat 'inline' as more of a hint which the compiler is likely to ignore; during compiling it will do various stages of analysis to decide if a function should be inlined or called directly depending on what is going on at the call site at that moment. This can mean that calling function 'foo' from two locations might result in it being inlined in one but not another. However this only applies to functions the compiler can see all of which is at the 'translation unit' level (pretty much a single .cpp + headers) as that is all the code it has access to; so if a function is fully defined in a header it can potentially be inlined.

Note the 'only code it can see' above; this is where link time code generation and whole program optimisation enters the picture.

The linker has a much more complete picture of the code and as such can run its own anaylsis to determine what to inline when. So this could result in a function being defined in one .obj file and called from two others being inlined in one case but not the other depending on the call site.

The code can also be physically moved around in the executable to try and improve locality (a function is only called in a few places, so if those places are close together then putting the function close to them is good) and this would require adjustment to the code itself (compiler might have used a 'long' jump but with the code moved locally the linker can emit the 'short' version instead).

Simply put the compilers do a lot of clever stuff these days, some better than others, and it is a very active area of research still when it comes to applying optimisations etc.
0

Share this post


Link to post
Share on other sites
Multiple OBJ files foils inlining, unless using link time code generation (/LTCG).

If you turn off function level linking, the whole obj gets linked in if ANY function or data in the OBJ is referenced in the rest of the program. This can be an issue if you care about space (as we definitely do on consoles).

Multiple OBJs can be a problem if a header file defines static variables. This will cause the variable to exist 'without a name' in each of the obj files and get linked into the final binary multiple times (another space issue, and can be hard to track down the cause) Edited by Zoner
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