From 8263e2a4da1558dc29f61f929f0d99ac3abac0bb Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Thu, 30 Dec 2021 14:50:48 +0100 Subject: [PATCH] The AD and DA hybrid XSPICE bridges consume a lot of memory (one state per time step added). Memory of previous time steps is not recovered. Patch #109 by Giles Atkinson reduces memory consumption dramatically (> factor of 10). --- src/xspice/evt/evtaccept.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/xspice/evt/evtaccept.c b/src/xspice/evt/evtaccept.c index 433fb5abe..251029e88 100644 --- a/src/xspice/evt/evtaccept.c +++ b/src/xspice/evt/evtaccept.c @@ -140,12 +140,26 @@ void EVTaccept( num_modified = state_data->num_modified; /* Loop through list of items modified since last time */ for(i = 0; i < num_modified; i++) { + Evt_State_t *state; + /* Get the index of the state modified */ index = state_data->modified_index[i]; - /* Update last_step for this index */ - state_data->last_step[index] = state_data->tail[index]; /* Reset the modified flag */ state_data->modified[index] = MIF_FALSE; + /* Get the last saved state for this instance. */ + state = *(state_data->tail[index]); + /* Dump everything older on the instance-specific free list, + * recreating the setup after the initial calls to cm_event_alloc(). + */ + if (!state) + continue; + if (state->prev) { + state->prev->next = state_data->free[index]; + state_data->free[index] = state_data->head[index]; + } + state_data->head[index] = state; + state_data->last_step[index] = state_data->tail[index] = + &state_data->head[index]; } /* Reset number modified to zero */ state_data->num_modified = 0;