Advertisement

Question about Config Groups

Started by June 10, 2010 12:18 PM
1 comment, last by _orm_ 14 years, 5 months ago
One thing that is troubling me. I am setting up something where I need to register global functions to the engine then un-register them when it is done to conserve memory. It seems to me that ConfigGroups would work for this purpose, but I want to confirm something.

Lets say I have a module named "MODULE" and a config group of global functions that only that module can use called "MOD_FUNCS", giving us the following code

int r;engine->BeginConfigGroup("MOD_FUNCS");r=engine->RegisterGlobalFunction("void foo()",asFUNCTION(foo), asCALL_CDECL); assert(r>0);r=engine->RegisterGlobalFunction("void bar()",asFUNCTION(bar), asCALL_CDECL);assert(r>0);engine->EndConfigGroup();// then create the module using CScriptBuilderr=module_builder.StartNewModule("MODULE");assert(r>0);engine->SetConfigGroupModuleAccess("MOD_FUNCS","MODULE",true); // set the module to access the config group.r=module_builder.AddSectionFromFile(script.c_str());assert(r>0);r=module_builder.BuildModule();assert(r>0);// do stuff with the module where the script uses the functions in the config group.// now everything is done and the functions in the config group are no longer needed and the module is also not needed.r=engine->DiscardModule("MODULE");r=engine->RemoveConfigGroup("MODULE_FUNCS");


My question is this, after the config group "MODULE_FUNCS" as been removed, are the functions that were registered to it also released or are they still being held by the engine instance?

If they are, what are other ways I could variably add and remove global functions, or better yet, register functions to a module directly. My goal is for certain features of my application, I want to avoid the need to having the client have to import functions from another module in order to use them, as well as keep memory usage low when such functions are not needed.
When the config group is removed the registered functions, properties, and types are released.

However, the engine will only allow you to remove a config group if there are no references to the functions, properties, or types still active. You must check the return value from the RemoveConfigGroup in order to determine if the group was really removed.

If it wasn't it means that there is still someone using it. You may then need to discard script modules, and run the garbage collection till the end in order to release all those references.

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

Advertisement
Thanks for clearing that up. I don't forsee that locks will be much of a problem for me as the functions would only be added and released in isolated cases of the application.

This topic is closed to new replies.

Advertisement