SomRenewNoInitNoZero

This method creates a new object instance using a passed block of storage.

For backward compatibility, this method does not take an Environment parameter.


 * Original Class : SOMClass

Syntax
SOMObject somRenewNoInitNoZero (SOMClass receiver, somToken memPtr)

Parameters

 * receiver (SOMClass) : A pointer to the class object that is to create the new instance.


 * memPtr (somToken) : A pointer to the space to be used to construct a new object.

Return Code

 * rc (SOMObject) : The value of newObject is returned, which is now a pointer to a valid, initialized object.

Remarks
The somRenew method creates a new instance of the receiving class by setting the appropriate location in the passed memory block to the receiving class's instance method table. Unlike somNew, these "Renew" methods use the space pointed to by memPtr rather than allocating new space for the object. The somRenew method automatically re-initializes the object by first zeroing the object's memory, and then invoking somDefaultInit; somRenewNoInit zeros memory, but does not invoke somDefaultInit. somRenewNoInitNoZero only sets the method table pointer; while somRenewNoZero calls somDefaultInit, but does not zero memory first.

No check is made to ensure that the passed pointer addresses enough space to hold an instance of the receiving class. The caller can determine the amount of space necessary by using the somGetInstanceSize method.

The C bindings produced by the SOM Compiler contain a macro that is a convenient shorthand for _somRenew(_className).

Example Code

 * 1) include 

main { void *myAnimalCluster; Animal animals[5]; SOMClass animalClass; int animalSize, i;

animalClass = AnimalNewClass(Animal_MajorVersion,Animal_MinorVersion); animalSize = _somGetInstanceSize (animalClass); /* Round up to double-word multiple */ animalSize = ((animalSize+3)/4)*4; /*  * Next line allocates room for 5 objects * in a "cluster" with a single memory- * allocation operation. */ myAnimalCluster = SOMMalloc (5*animalSize); /*  * The for-loop that follows creates 5 initialized * Animal instances within the memory cluster. */ for (i=0; i     animals[i] =     _somRenew(animalClass, myAnimalCluster+(i*animalSize));  /* Uninitialize the animals explicitly: */  for (i=0; i     _somUninit(animals[i]); /*  * Finally, the next line frees all 5 animals * with one operation. */ SOMFree (myAnimalCluster); } 

Methods

 * somGetInstanceSize
 * somDefaultInit
 * somNew