• 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
Tibetan Sand Fox

Is that way of using constructor really better ?

29 posts in this topic

[quote name='SiCrane' timestamp='1349528801' post='4987380']
IIRC, it's so that member variables would satisfy the last constructed, first destroyed order that is the general case for variables whose lifetime are managed by the compiler
[/quote]Ah that makes sense -- if it went off the initializer list, and a class had 2 different constructors with different initialization orders, then the destruction order would no longer be the opposite ([i]unless you error'd on mismatching initialization orders, or generated multiple virtual destructors[/i]).
That said, I'd still prefer the language to do that -- either generate an error if I've got multiple constructors with different orders, or simply warn me that my destruction order has become implementation defined due to the conflicting constructors.
[quote]In theory, the padding/member variable order issue was addressed by allowing the compiler to reorder position of member variables with different access specifiers, but in practice compilers don't actually take advantage of that.[/quote]Wait, the spec says the compiler is allowed to do that? Even after a decade of using this language I'm still learning new quirks...
0

Share this post


Link to post
Share on other sites
C++03 allowed it anyways. I don't have a copy of C++11 handy right now, but I seem to remember it walked back that flexibility somewhat. The verbiage for C++03 goes:
[quote]
Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses within a class object. The order of allocation of nonstatic data members separated by an access-specifier is unspecified.[/quote]
Since it says "intervening access-specifier" you could, in theory, stick a public: or whatever in front of each and every member variable and the compiler could reshuffle them to minimize padding.
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1349525505' post='4987371']
[quote name='taz0010' timestamp='1349502023' post='4987326']
Personally if I have [b]primitive variables[/b] that I need to initialise in a specific order, I'm not going to rely on the class definition order to do it, and that means good old fashioned assignment with the = operator.
[/quote]
I emboldened the key part in the above quote -- primitive types aren't default initialized, so when it comes to assigning their default values, then the choice of using the initializer list, or assignment in the constructor body is [b]purely a choice of style[/b]. They both generate the same results ([i]unless of course, another item in the initializer list is initialized using the value of a primitive member[/i]), so saying one is more correct than the other is nothing more than a style war.[/quote]
Which is sortof the point I was poorly trying to make. Avoiding the initialization lists because it's 'not reliable' doesn't make sense to me, and being a choice of style, to call one less reliable when they are both standardized is misinformation. What you're saying though, is one is more resistant to side-effects of later code changes, and not that it's non-standard.

[quote name='taz0010' timestamp='1349502023' post='4987326']Personally if I have primitive variables [u]that I need to initialise in a specific order[/u], [u]I'm not going to rely on the class definition order to do it[/u], and that means good old fashioned assignment with the = operator.[/quote]

I misunderstood taz's point - I thought he was implying that the class definition order is non-standardized, or unreliable. But you are saying that the [i]humans[/i] during a crunch are unreliable, and easily mess up important initialization orders by mistake. That makes sense!

Offtopicly: Re-ordering the member variables by size seems rather silly to me (about as silly as re-ordering them based on alphabetizing their variable name), I've never worked in such an environment so there is probably have a good reason for it. Personally, in the few (having not worked on a compact platform) situations I needed to micro-manage the size of variables, I left comments mentioning each of their sizes. How does re-ordering by size help?

([size=2]I realize primitive types aren't initialized, and was mixing up initialization with construction - whoops![/size]) Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites
On most platforms types have alignment, a multiple of a memory address that it is most efficient to read or write that type. For primitives, alignment is generally equal to size. For structs and classes, alignment is generally equal to the alignment of the member variable with the most restrictive alignment requirements. On some platforms alignment is actually necessary to prevent a hardware exception; on other platforms it simply requires more clock cycles. For this reason C++ compilers will arrange structures so that every member variable is placed at proper alignment. Let's say you have the structure
[code]
struct A {
short aa;
int bb;
short cc;
};
[/code]
With a two byte short and a four byte int, aa will generally be put at an offset of 0 into the struct, bb at an offset of 4 and cc at an offset of 8. Since A has an alignment of the most restrictive member, it will have an alignment of 4, and the whole structure will take up 12 bytes. However if you reorder the variables:
[code]
struct A {
short aa;
short cc;
int bb;
};
[/code]
The aa will have an index of 0, cc an index of 2 and bb will have an index of 4, and the whole struct will take up only 8 bytes.
2

Share this post


Link to post
Share on other sites
[i]*slaps forehead*[/i] I've forgotten about alignment issues. Thank you for the explanation!
1

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