Forums > Dev

Can I make a call to make a new instance fail safely

August 20, 2012 | 4:38 pm

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



tap
August 24, 2012 | 8:15 pm

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


Viewing 2 posts - 1 through 2 (of 2 total)