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

char* or const char* in binding functions to script

3 posts in this topic

Hi!

In script we can use only string but they are very very slow because using of strings leads to lots of allocations.

Simple example:

strint str;
str = "lots" + " of " + "allocations";

this simple line of code leads to 7 allocations and 3 deallocations. If we put 10 such line of code and we got 70 allocations and 30 deallocations in single frame. And this is awefull because this becaume bottlenck.

This problem may gone if i would bind functions like void opAdd(const char* in) / void opAdd(char* in) but i can't do that (((

Also in c++ code we never use std::string, we use only char str[] and we never have problems with unnecessary allocations. Also, because
we can't bind function with char* as parameter almost always we got unnecessary allocation when we call c++ function from script containing string as parametr.

Is there are any solution to avoid problem with string allocations? Do not use strings not a option (((
0

Share this post


Link to post
Share on other sites
Even if you could bind const char * strings to AngelScript (I don't know if it's possible, someone else might know better), it doesn't solve your example. E.g. the following would not work
[code]
void foo(const char *str);
int main()
{
foo("lots" + " of " + "allocations");
}
[/code]
Being able to register function foo to AngelScript helps nothing, since you could not call it like that anyways (from either side of the script boundary).

The C++ solution to the large number of allocations and deallocations in your example are move constructors ( [url="http://msdn.microsoft.com/en-us/library/dd293665.aspx"]http://msdn.microsof...y/dd293665.aspx[/url] ) introduced in C++11, which reduce the amount of unnecessary temporary object allocations and deallocations that need to be made. Edited by clb
0

Share this post


Link to post
Share on other sites
In C++ char[] or char* is convenient and efficient, but it requires that the programmer know what he's doing so that the memory is properly managed. In AngelScript the programmer shouldn't have to have much knowledge to know how to work with strings, nor should he be able to (willfully or not) do something wrong like deallocate a local variable.

That said. It is possible to register char* by registering a value type to represent the pointer, e.g.

[code]
engine->RegisterObjectType("charptr", sizeof(char*), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE);
[/code]

You can then register the functions and objects to take this type wherever the application function takes a char* or const char*. Doing it like this will force the script writer to manually do the necessary memory allocations and deallocations, so be aware of this and prepare yourself for memory leaks or crashes due to badly written scripts.

You may also want to consider implementing your own custom string object rather than use the std::string. With a custom string object you can fully control how the memory is allocated and deallocated, and thus reduce the overhead to a minimum without sacrificing the "sandboxing" of the scripts. Perhaps, just a custom allocator for std::string is enough to do this.
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