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

perfomances issues with classes in array

8 posts in this topic

Hi!

 

In script we store data in angel script classes. Also we have array of classes.

 

Sample look like:

 

class StoreData

{

   int data1, data2;

   float data1, data2;

}

 

array<StoreData> data;

 

But big problem lie in fact that in memory 100 elements of array is just pointers. Actual data lies randomly in memory, so if we try to access to field data1 of 100 elements in loop we catch many many cache misses. Also we cannot binary save this array we must access to every field of every element in array.

 

So classes in array is big bottleneck.

 

Is it possible to avoid this issue?

0

Share this post


Link to post
Share on other sites
Use a custom allocator and move data to be continuous when its time to resize the container.
Alternatively you could wrap std::vector. ISO standard dictates std::vector is guaranteed to be continuous.
I chose std::vector route.

edit:
In addition, AngelScript allows you to have your own custom malloc and free. This is not utilized in scriptarray addon. Edited by saejox
0

Share this post


Link to post
Share on other sites

Thanks for reply!

 

But using custom allocator it is not solution. Script array already store data in one chunk. But script class itself allocated by AngelScript so array it is just array of pointers to angel script representation of class. I can not hack Angel Script to make allocate arrays of classes in one chunk.

0

Share this post


Link to post
Share on other sites

Hi!

 

Thanks to link leads to documentatios. But please before answer again try to understend what i want to achieve.

In c++ if i define array like this -

 

struct Data

{

    float a,b,c;

}

std::vector<Data> data;

 

when i go throught loop of each element of array access speed to element will be maximized because data lie in cache. If I repace array to

 

std::vector<Data*> data;

 

access to each element may leed to p?tention cache miss becase pointers in array may point at random places in memory. If accessed data lie all in one chank there still potentional chace miss.

 

cusom allocators from angel script is good but that mean write very complicated memory manager because i can call from script resize of array at any time and how my manager supose to understend that i must resize exetly that array? it is almost imposible without hacking angelscript.

 

i understend - angel script goes by way of sand box. But sand box means big perfomance problems. We currently work on mobile title and angel script is big big perfomance issue. I prefer get more control points to trade safety to speed.

0

Share this post


Link to post
Share on other sites

Sorry, i can't think anything other than custom allocators.

You can position your data any place that way. Won't be easy as you said.

There are many additional benefits using custom allocators: leak detection, memory statistics, defragmentation etc..

 

You might also consider creating a static array container. It still requires the custom allocator, but it's easier to write for sure.

AngelScript doesn't have static arrays yet.

Edited by saejox
0

Share this post


Link to post
Share on other sites

Is the StoreData class a script class or an application registered class?

 

All script classes are reference types. Multiple instances of reference types cannot be allocated in a single block, because the lifetime of each instance is determined by the last reference to the object instance and not the memory block itself. Also, you cannot move the position of a reference type to a different memory location, so a resize of the memory block wouldn't be possible.

 

If the StoreData is a registered class then you should make sure to register it as a value type. The CScriptArray add-on currently doesn't allocate value types in single memory block, only primitive types are allocated in single block at the moment. However, there is no restriction to change it to also allocate value types this way. If you do change it, I would be happy to include this change in the SDK.

0

Share this post


Link to post
Share on other sites
StoreData class is a script class

I will be happy to modify CScriptArray but how i can overide angel script to allocate data in my buffer when angelscript calling CreateScriptObject? I only think about temperiory binding custom allocator but i am not shure what happens when angel script call ReleaseScriptObject. Maybe i need use some markers in allocated blocks. May be i need use some thing else?</p> Edited by _Engine_
0

Share this post


Link to post
Share on other sites

As StoreData is a script class I would recommend against trying to allocate them inline in a single memory block. As I mentioned before the script class is a reference type, and if the script holds a reference to one of the array elements you would invalidate the reference if the array is resized. Ideally the script language would support declaring value types for simple structs like this, but this is something that is still far away from being implemented.

 

Instead I'd suggest you create a custom container class. Instead of storing the actual StoreData class, it could store just the content of the class. Similarly to how the CScriptArray works the container can check the structure of the script class upon creation and decide how to store its content. For example for the StoreData class, the structure is very simple and the content can be copied with a simple memcpy from the position of the first member.

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