Can I make a call to make a new instance fail safely
I am creating an object with large variable t_atom arrays as storage for attributes.
In order to allocate memory for the storage I am calling a memory allocator in the new routine. Assuming this fails, what is a safe way to prevent my object from being created, as I have no way of telling max that the attributes should not be accessed?
The attributes have a custom setter in case it is relevant.
I assume returning a null pointer in new might work, but should I clean-up the object allocation first?
Alex
Hi Alex,
Yes, you should return NULL from your new method. This is what we do where appropriate. And, yes, you should also clean-up anything you've alloc'd from the heap in the process.
Cheers,
Tim