Bull DPX/20 Uživatelská příručka Strana 115

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 424
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 114
SOM Kernel Reference 1-103
Example
#include <animal.h>
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 &odq.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<5; i++)
animals[i] =
_somRenew(animalClass, myAnimalCluster+(i*animalSize));
/* Uninitialize the animals explicitly: */
for (i=0; i<5; i++)
_somUninit(animals[i]);
/*
* Finally, the next line frees all 5 animals
* with one operation.
*/
SOMFree (myAnimalCluster);
}
Original Class
SOMClass
Related Information
Methods: somGetInstanceSize, somInit, somNew
Zobrazit stránku 114
1 2 ... 110 111 112 113 114 115 116 117 118 119 120 ... 423 424

Komentáře k této Příručce

Žádné komentáře