Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

[PATCH] POD members in object memory


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 GGLucas   Members   -  Reputation: 140

Like
1Likes
Like

Posted 31 October 2013 - 04:32 PM

Inspecting some of the bytecode output from script class constructors one thing I noticed was that application POD classes were being allocated on the heap in their own little chunks of memory. This was mainly an issue for small things like 2d/3d vectors, rectangles, etc. The worst offender of it all being our 'Color' class - a shortcut for representing colors as 32-bit rgba integers which was being allocated into its own heap memory and adding a 64-bit pointer to the class.

 

The attached patch changes the behaviour of POD application class typed members to be stored directly in the object's allocated memory block instead. It passes angelscript's test suite, and we've been using it in our project for a few weeks now.

 

Feel free to use/alter if you're interested in using it.

 

 

 

 

Two small miscellaneous things that I'm going to shoehorn into this thread:

 

The test suite needs C++11 to compile, so the makefile needs to tell gcc to use it:

Index: sdk/tests/test_feature/projects/gnuc/makefile
===================================================================
--- sdk/tests/test_feature/projects/gnuc/makefile	(revision 1759)
+++ sdk/tests/test_feature/projects/gnuc/makefile	(working copy)
@@ -1,7 +1,7 @@
 # Test Framework GNUC makefile
 
 CXX = g++
-CXXFLAGS += -ggdb -I../../../../angelscript/include -Wno-missing-field-initializers
+CXXFLAGS += -std=c++11 -ggdb -I../../../../angelscript/include -Wno-missing-field-initializers
 SRCDIR = ../../source
 OBJDIR = obj

Also, there's a problem with the context used in ScriptObjectFactory: if script engine A calls an application function that wants to create a script object in script engine B, ScriptObjectFactory will nest into the context from engine A, creating a crash. This occurred in some of our cross-engine communication functions. We added a check to not use nesting if the active context is from a different engine, but there should probably be a way for the application to provide asIScriptEngine::CreateScriptObject() with the context to use for the call since creating contexts is expensive.

Index: sdk/angelscript/source/as_scriptobject.cpp
===================================================================
--- sdk/angelscript/source/as_scriptobject.cpp	(revision 1759)
+++ sdk/angelscript/source/as_scriptobject.cpp	(working copy)
@@ -53,12 +53,17 @@
 	ctx = asGetActiveContext();
 	if( ctx )
 	{
-		r = ctx->PushState();
+		if( ctx->GetEngine() == engine )
+		{
+			r = ctx->PushState();
 
-		// It may not always be possible to reuse the current context, 
-		// in which case we'll have to create a new one any way.
-		if( r == asSUCCESS )
-			isNested = true;
+			// It may not always be possible to reuse the current context, 
+			// in which case we'll have to create a new one any way.
+			if( r == asSUCCESS )
+				isNested = true;
+			else
+				ctx = 0;
+		}
 		else
 			ctx = 0;
 	}

Attached Files



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
0Likes
Like

Posted 31 October 2013 - 06:19 PM

I haven't even completely integrated your previous patch yet and here you're providing another one. :)

 

Changing the code to allocate the value types inline has been on my to-do list for quite some time. Thanks a lot for saving this time for me. 

 

I'll probably not include this for 2.28.0 which is near completion, but I'll definitely look into adding it for the next release after that.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Andreas Jonsson   Moderators   -  Reputation: 3437

Like
0Likes
Like

Posted 14 December 2013 - 09:26 AM

I've included this patch in revision 1799.

 

You seem to have a really good grasp of the internal workings of AngelScript. :)


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS