Limitation of max. numbers of objects


    Sep 12 2017 | 5:49 pm
    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.

    • Sep 13 2017 | 11:39 am
      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.
    • Sep 14 2017 | 8:32 am
      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.
    • Sep 14 2017 | 2:09 pm
      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?
    • Sep 14 2017 | 2:26 pm
      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.