Top Up Prev Next Bottom Contents Index Search

6.7 Class Plasma

Class Plasma is a pool for particles. It is derived from ParticleStack . Rather than allocating Particles as needed with new and freeing them with delete, we instead provide an allocation pool for each type of particle, so that very little dynamic memory allocation activity will take place during simulation runs. All Plasma objects known to the system are linked together. As a rule, there is one Plasma for each type of particle; however, each of these objects is of type Plasma, not a derived type. At all times, a Plasma has at least one Particle in it; that Particle's virtual functions are used to clone other particles as needed, determine the type, etc. The constructor takes one argument, a reference to a Particle. It creates a one-element ParticleStack, and links the Plasma into a linked list of all Plasma objects. The put function (for putting a particle into the Plasma) adds a particle to the Plasma's ParticleStack. As a rule, it should not be used directly; the Particle's die method will automatically add it to the right Plasma (future releases may protect this method to prevent its general use).

Particle* get(); 
This function gets a Particle from the Plasma, creating a new one if the Plasma has only one Particle on it (we never give away the last Particle).

int isLocal() const;
Returns localFlag.

static Plasma* getPlasma (DataType t);
Get the appropriate global Plasma object given a type.

static Plasma* makeNew (DataType t);
Create a local Plasma object given a type.

void makeLock(const PtGate& master);
Create a lock for the Plasma.

void delLock();
Delete lock for the Plasma. No effect on global plasmas.

short incCount();
Increase reference count, when adding reference from PortHole to a local Plasma. New count is returned. Global Plasmas pretend their count is always 1.

short decCount();
Decrease reference count, when removing reference from PortHole to a local Plasma. New count is returned. Idea is we can delete it if it drops to zero. Global Plasmas pretend their count is always 1.

DataType type(); 
Returns the type of the particles on the list (obtained by asking the head Particle).

static Plasma* getPlasma(DataType type); 
Searches the list of Plasmas for one whose type matches the argument, and returns a pointer to it. A null pointer is returned if there is no match.



Top Up Prev Next Bottom Contents Index Search

ptolemy@eecs.berkeley.edu
Copyright © 1990-1997, University of California. All rights reserved.