Sign in to follow this  
AgentC

asSFuncPtr executable size optimization

Recommended Posts

For my personal use (Urho3D engine) I've done some modifications to AngelScript, some of which are dubious, but here's something that shouldn't be much destructive to performance, but reduce the executable size, possibly even by a hundred KB or so, if there's a lot of classes & functions being registered.

 

It has to do with the template functions for initializing asSFuncPtr's. While the original template code memclear's the function pointer object (which is possibly also inlined), and then sets the flag member variable according to whether it's a function or method

 

 

// Specialization for functions using the generic calling convention
template<>
inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
{
    asSFuncPtr p;
    asMemClear(&p, sizeof(p));
    p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);

    // Mark this as a generic function
    p.flag = 1;

    return p;
}

 

 

I've created a non-inline constructor for asSFuncPtr, which does the memclear and sets the flag

 

 

asSFuncPtr::asSFuncPtr(asBYTE f)
{
    asMemClear(this, sizeof(asSFuncPtr));
    flag = f;
}

 

 

By using that, the template functions become shortened and should consume less memory:

 

 

// Specialization for functions using the generic calling convention
template<>
inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
{
    asSFuncPtr p(1);
    p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);

    return p;
}

 

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