Limitation of max. numbers of objects
Is it possible to program a max extension that limits the maximum number of objects (instances) at runtime?
This is for a hardware-interface-object. Depending on the number of connected devices, only one instance should be able to be generated.
You can use a global variable to store an instance count. Check this in your object_new function and if too high, return null (and ideally post an error message to the console) to indicate that object construction failed. Otherwise, increment the count, and decrement it in the object_free function.
Thank you, David. There is no accessible data structure, or so, from which the number of the instance could be read out? But I think this hint will work for me.
I've tried it, and it works great! But new wishes arise: When I finish an instance, is there a mechanism to inform the others about it?
If you want to use a data structure rather than an instance count, you could try using a global hashtable initialized in your externals ext_main function. You would however need to free it at program exit using a quittask (look up quittask_install in the API docs).
For notifying other classes, you'll want to look at the object notification system. Check out the master.c and servant.c objects in the misc folder of the Max SDK.