aconstlink / motor

Software Framework for Audio/Visual/Interactive Real-Time Applications
MIT License
3 stars 0 forks source link

Wire variable needs optimization #109

Closed aconstlink closed 3 weeks ago

aconstlink commented 1 month ago

The wire variable class uses a lot of memory. The class itself is nicely designed and just "feels" right but storing subvariables as fixed objects add too much memory consumption.

For example, a wire variable of type motor::wire::variable< motor::math::m3d::transformation< float > >

requires 540 bytes! That is too much.

It stores all its possible subvariables as objects, so it may be better to store a single pointer to those, so that it only gets instanced if sub variables are used.

aconstlink commented 3 weeks ago

I decided to split the variable type into a detailed and a simple variable type. This way a single type does not have to do all the differences in how the variable is actually used.

The simple type now does not have any sub members, while the detailed type has all submembers.

The usage is very similar to as before:

motor::wire::vec3fv_t var( "pos" ) ; // simple variable
motor::wire::vec3fvd_t var( "pos" ) ; // detailed variable

The variables are distinguished by a trait using template argument

template< typename T, typename trait_t >
class variable : public any, public trait_t ;

The trait can be motor::wire::simple_trait or motor::wire::detailed_trait.

This way a variable can be exchanged during run-time by only swapping the most top in/output slots to the other type.

aconstlink commented 3 weeks ago

Swapping variables still need to be implemented: #110