Sign in to follow this  

RequestContext() / ReturnContext() question

This topic is 838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On this page, the documentation says:
It is seldom necessary to maintain more than one script context at a time, with the only exceptions being when a script calls an application function that in turn calls another script before returning, and if multiple scripts are running in parallel.
 
Try to avoid associating a unique context with each object that may need to call scripts. Instead keep a shared pool of contexts that can be requested by the objects on a need-to basis.

 

 

It sounds like that's what aslScriptEngine::RequestContext() and aslScriptEngine::ReturnContext() do for me, as convenience functions?
So if I have several scripts I'm wanting to run in parallel (not multithreaded, but with their execution being suspended and resumed at different times with their states needing to be preserved), can I just let AngelScript handle the pool of contexts for me using the two above functions?

Share this post


Link to post
Share on other sites

I'll need to make a clarification on that page in the manual. Thanks for brining this up.

 

RequestContext and ReturnContext does not implement the context pool for you. However, they are there to simplify the implementation of a context pool. By default, these methods internally calls CreateContext and Release, but if you register the context callbacks they will call those instead of CreateContext/Release. Registering the context callbacks will allow the application to prepare the context for the engine's internal calls too, thus allowing the application to trace/debug even these internal calls (internal calls happens for example when initializing global variables or destroying objects from the garbage collector). The add-ons are also using the RequestContext and ReturnContext calls so all goes to the same place.

 

A basic implementation of a context pool is described here on the fine tuning page in the manual.

Share this post


Link to post
Share on other sites

This topic is 838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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