Object_alloc zeroed ?

Jan 17, 2013 at 3:24pm

Object_alloc zeroed ?


I’m reading an old thread ( http://cycling74.com/forums/topic.php?id=5339 ) and it seems that with object_alloc( ) i should not rely on getting a pointer to a zeroed structure ? Is that true ?

Jan 17, 2013 at 9:05pm

From Max 5 onwards, this will be a zeroed struct, unless you use CLASS_FLAG_DO_NOT_ZERO. If you need compatibility for 4.x in your external, you should not rely on this.

Jan 18, 2013 at 6:20am


Thanks for those clarifications.

It seems that CLASS_FLAG_DO_NOT_ZERO is not defined nor in Max 5 nor in Max 6 SDKs.

Jan 18, 2013 at 8:30pm

Sorry this is a new addition. Possibly in some of the later versions of 6.0.x SDK, but definitely will be in the forthcoming 6.1 SDK.

In general, this is only provided for some very specific cases in which you wish to eliminate the performance cost of zeroing the memory. We only use this for fundamental nobox objects which are allocated with high frequency (e.g. hashtabs, linklists, etc.).

Unless you’re seeing object_alloc show up as a hot spot in a profiler like shark, I would suggest that you don’t worry about it.

The main answer is, yes, you can rely on your memory to be zeroed.

Jan 19, 2013 at 7:03am


Good to know, thanks.

Jan 16, 2014 at 7:25am

Does this also apply to max_jit_object_alloc() and jit_object_alloc()?

In all cases, I think there is value in updating the SDK text and examples to declare and reflect that the struct is zero’d. For example:
- SDK section 3.4, update that this object_alloc() routine first init’s the whole struct to zero
- SDK section 3.4, update that example to set x->s_value to a non zero value
- SDK section 19.2, update that example to set x->myval to a non zero value
- SDK Module documentation it is vague writing, “and initialize its object header”
- SDK Module documentation reference the CLASS_FLAG_DO_NOT_ZERO and how it applies to this call


You must be logged in to reply to this topic.