Writing S-Functions    

Making C++ Objects Persistent

Your C++ callback methods might need to create persistent C++ objects, that is, objects that continue to exist after the method exits. For example, a callback method might need to access an object created during a previous invocation. Or one callback method might need to access an object created by another callback method. To create persistent C++ objects in your S-function:

  1. Create a pointer work vector to hold pointers to the persistent object between method invocations:
  2. Store a pointer to each object that you want to be persistent in the pointer work vector:
  3. Retrieve the pointer in any subsequent method invocation to access the object:
  4. Destroy the objects when the simulation terminates:

  Source File Format Building C++ S-Functions