Please enable JavaScript to view this site.

Vensim Help

The use of Constant and Data definition functions require that memory be allocated to store information.  For Constants, this memory is a 2 dimensional array of value (even if the function is being invoked for a scalar).  For Data the memory is an array with a number of rows determined by the subscript used when the function is called and a number of columns determined by the number of times available.  In addition, Data requires that a Time vector be allocated and populated.

The easiest way to allocate memory is to use the VGV->alloc_simmem function call back (or the exported function vensim_alloc_simmem) described below.  For constants this can simply be called with the information passed from Vensim.  For Data, you must first determine the number of time values to include, then call this function.

The memory that is allocated to store Data (including the time vector) will be referenced again and again and must not be reused in a different call to a Data Definition function.  This restriction does not apply to Constant definition functions since the memory used to pass constant arguments will be accessed once directly after the call to the Constant Definition function and then not referred to again.

If you use the VGV->alloc_simmem function to allocate memory you do not need to free the memory.  Vensim will automatically do this when the simulation has been completed.  If you use an alternative allocation technique you will need to free the memory in your simulation_shutdown routine (when it is called with finalflag==1).