Best Way To Declare Constant Variables Custom Object


#1

What's the best way/place to declare a constant variable in a custom Axo object?
I want to make a custom object that requires several data arrays/lookup tables, so want to know the most resource-efficient way to do this.

Cheers,

a|x


#2

Object "attributes" are known at compile time, and cause the string "attr_name" anywhere in the object code to be replaced with the attribute value.


#3

Oh, OK, so I'd declare them in the attributes block of the object XML.

Would I just declare them as standard C variable type (int32_t etc.)?

To be clear, I'm talking about lookup tables and other constants in arrays, so I wouldn't want them to be exposed as object options in the Patcher.

a|x


#4

I realise I meant 'static' where I said 'constant'.

Is there any mileage in declaring lookup tables etc. as static, and how/where would I do that, if so?

Let's assume I want to declare as array of 32 bit integers, as an example.

a|x


#5

const int32_t p[4]={1,2,3,4};
in the "Local data" section


#6

I see. Are there advantages to doing this, over declaring a standard dynamic variable, in term of memory-management efficiency of compiled code?

a|x


#7

we dont allocate memory dynamically (e.g dont start using malloc etc).
the above 'theoretically' is allocated on the stack. (unless you declared it static, but then you would have issues with multiple instances of your object!)
the next steps, come into the realms of the compilers optimiser, since you declare it const, then it knows it doesn't have to have multiple instances for each object, since they are all the same, and cannot change... i.e. it will probably end up like a static BUT it may be able to do further optimisation, e.g. if you referred to and index explicitly, it could substitute the hard coded value (and if thats combined with other constants it can then further optimise that!)

I would point out this is all 'standard C', none of this is really specific to axoloti.

btw: if its a large array, then the other consideration is to potentially add the sdram attribute to it, as there is more space there. but this seems unlikely given your wanting to fill it with constant values.


#8

Thank you thetechnobear. I should do a bit of reading on C. I did start a short course in it a very long time ago, but wasn't able to complete it because my circumstances changed, and I could no longer make it to the sessions.

a|x


#9

Oh good, so I don't have to get involved in manual garbage-collection. That's a relief..

a|x