Jump to content
  • Advertisement
Sign in to follow this  
39ster

Disadvantages of generic..?

This topic is 3776 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

In the string class addon you have generic functions/operators and native functions/operators. Why do you have both? Why not just generic?

Share this post


Link to post
Share on other sites
Advertisement
The generic calling method is the only one available when AS_MAX_PORTABILITY is defined. In order to support this directive generic methods need to be implemented along side their normal counterparts.

Share this post


Link to post
Share on other sites
The generic functions have a bit more overhead than the native functions, since they normally wrap the native functions in order to transport the data between AngelScript and the application.

For the add-ons I implement both, to allow speed where native functions are supported, yet maintain portability where they are not.

Share this post


Link to post
Share on other sites
Native calling conventions differs depending on three factors: target CPU, target OS, and compiler used. AngelScript uses customized assembly code for each combination that is supported.

AngelScript does support native calling conventions on most of the major platforms, but there are still some platforms that only work with the generic calling convention (which is pure C++, thus works everywhere).

List of supported platforms

Share this post


Link to post
Share on other sites
Ok one last question. From a native function, how do i return an object? For example "string toLower(string& in)". In generic you do something like this:

*(asCScriptString**)gen->GetReturnPointer() = new asCScriptString()
how do i do it in native?

Share this post


Link to post
Share on other sites
Since you're using asCScriptString you cannot return the object by value in native mode (since that requires the object to be placed on the stack, which is not compatible with reference counting). Instead you should return the object with an object handle:


// Registered as "string @toLower(string &in)"
asCScriptString *toLower(std::string &s)
{
// Return the new string in an object handle
return new asCScriptString();
}

Share this post


Link to post
Share on other sites
Ok thankyou. Now i realise why i was getting a memory leak before. I defined it like

string& toLower(string &in)
i used the wrong symbol. Should of used "@".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!