Next: , Previous: The Objects base class, Up: Objects


5.23.3.4 Creating objects

You can create and initialize an object of a class on the heap with heap-new ( ... class – object ) and in the dictionary (allocation with allot) with dict-new ( ... class – object ). Both words invoke construct, which consumes the stack items indicated by "..." above.

If you want to allocate memory for an object yourself, you can get its alignment and size with class-inst-size 2@ ( class – align size ). Once you have memory for an object, you can initialize it with init-object ( ... class object – ); construct does only a part of the necessary work.