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

Using old array or stl

10 posts in this topic

Hi all what is better(Talking about memory and performance spped ) for store the  float vertex   using std::vector  vrtx<float> or use a raw array / like  float vrtx[]

 

thanks in advance 

0

Share this post


Link to post
Share on other sites

std::vector, under the covers, is just a managed array -- it has precisely the same layout in memory as a native array, or a contiguous block of dynamically-allocated memory, with the benefit that you neither have to allocate it statically (native array) or remember to delete it (dynamically-allocated memory). In C++ 11, std::vector (and other containers) also support move semantics which, properly afforded and called upon, eliminates redundant linear copy operations which a raw array cannot avoid AFAIK (perhaps as a particularly aggressive compiler optimization, given particularly formatted source code) -- A real-world example of this would be a function that returns the contents of a locally-declared array (which will need to be copied by the calling code), vs the same function which returns a locally-declared std::vector, which will simply move the std::vector internals between the locally-defined vector and the vector in the calling code, provided that either the return type is an rvalue reference (&&) itself, or std::move is invoked at the call-site.

 

In general, always prefer the *correct* standard container over native arrays and dynamic memory allocation -- there is some skill in choosing the right container based on your usage, and in configuring your build to not leave performance on the table (e.g. disable checked iterators) but the standard (or some other well-worn library) containers are always the right default choice -- they are faster, more robust, and contain far fewer bugs than anything you could hope to write yourself. There are times that they are not appropriate, but by the time you are ready to forego them in favor of some other solution, you will be experienced enough to not need to seek advice on these forums smile.png

Edited by Ravyne
0

Share this post


Link to post
Share on other sites
If the array is of a fixed size, prefer std::array over std::vector, but otherwise yes always use an STL container rather than a C array unless you have very strong reason not to.

You might see a perf difference for std::vector over a C array because vector throws exceptions on out-of-bounds access, meaning it has to check every access. I don't recall if std::array throws on out of bounds access, but I'd imagine it does. Debug builds will also have a higher cost due to the lack of inlining of the various accessor functions the STL containers use to emulate the arrays.

These perf differences are purely academic at the scale of game/app you're likely working on, though. Big AAA titles need to squeeze out the difference but then they still use STL-like containers; they just replace them with their own performance-conscious versions (which you shouldn't attempt unless you're ready to waste months of time in learning, development, test writing, etc.).
0

Share this post


Link to post
Share on other sites


You might see a perf difference for std::vector over a C array because vector throws exceptions on out-of-bounds access, meaning it has to check every access.

 

Only for random access (e.g. [] brackets) though, and only if exceptions are enabled, right? I would assume, perhaps incorrectly, that linear access through iterators at least amortizes the cost of two checks, if not avoiding it entirely -- perhaps modulo any funny-business one might be doing with the array size whilst walking it.

0

Share this post


Link to post
Share on other sites

Only for random access (e.g. [] brackets) though, and only if exceptions are enabled, right? I would assume, perhaps incorrectly, that linear access through iterators at least amortizes the cost of two checks, if not avoiding it entirely -- perhaps modulo any funny-business one might be doing with the array size whilst walking it.


Iterators are typically a bit worse in many respects - at least on non-optimized builds - as most STL implementations ship with complex "checked iterators" enabled by default. Different STLs have different ways of turning these off. One of the better reasons I have for writing a custom vector is just to ensure the iterators are plain ol' pointers, which can for some architectures turn your debug game from a slideshow into something almost playable. smile.png

I am so looking forward to getting to use VS2013's new /Zo option at work and seeing how it holds up. I'd really like something like GCC's -Og, but I guess I'll have to keep on waitin'.
0

Share this post


Link to post
Share on other sites


You might see a perf difference for std::vector over a C array because vector throws exceptions on out-of-bounds access, meaning it has to check every access. I don't recall if std::array throws on out of bounds access, but I'd imagine it does.

std::vector::at throws an exception, but std::vector::operator[] does not. Some light Googling indicates that std::array is similar.

 

Most implementations of the C++SL will do range checking, e.g. as an assertion, in debug builds, I believe at least some versions of VC++ went for range checking in all builds, but with a separate flag to disable them.

1

Share this post


Link to post
Share on other sites


std::vector::at throws an exception, but std::vector::operator[] does not. Some light Googling indicates that std::array is similar.

Yes, an implementation that does range checking and throws an exception for operator[] of the standard containers is non-conforming.  Most implementations are conforming in this respect, with an optional "debug" mode that needs to be explicitly enabled but is explicitly non-conforming.  At least one well-known vendor is non-conforming by default and the developer needs to go out of her way to make the implementation conform to the standard by flipping switches and pre-defining constants, which leads to lots of questions about poor performance in forums like these.

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