Previous: Synchronizing Spawned Functions Up: Synchronization Next: Pitfalls

Memory Management

The lifetime of a single-assignment object obeys the usual C++ scoping conventions. At the end of the block in which it is declared, a single-assignment variable goes out of scope, and is destroyed. In this case, the memory management is handled implicitly.

To create a single-assignment variable whose lifetime extends beyond the scope of its declaration, dynamic memory allocation can be used. Again, such allocation is completely consistent with how the allocation would be done for a constant value in C++, using the new operator. For example:


{
  sync int* a = new sync int;   
  ...
  *a = 3;
}

The declaration above creates a pointer to an undefined single-assignment integer. The assignment later defines the single-assignment integer referenced by a to be the value 3.

When dynamic memory allocation is used, C++ makes it the programmer's responsibility to deallocate this memory, freeing it for future use. This applies to single-assignment variables as well. Thus, corresponding to the declarations above, we might expect to see:


delete a;

paolo@cs.caltech.edu