mirror of
https://github.com/nasa/trick.git
synced 2025-02-20 17:22:52 +00:00
Don't resize active event array size with every operation #562
Started the active event allocation at 100 events. If more are needed, we add 100 allocations each time. The array is never reduced in size if events are deleted, events are moved to the front of the array and the remaining elements are set to NULL.
This commit is contained in:
parent
8be09638e7
commit
15bfd75b32
@ -146,6 +146,9 @@ namespace Trick {
|
||||
/** Number of active events\n */
|
||||
unsigned int num_active_events ; /**< trick_io(*io) trick_units(--) */
|
||||
|
||||
/** Number of active events allocated\n */
|
||||
unsigned int num_allocated ; /**< trick_io(*io) trick_units(--) */
|
||||
|
||||
/** All of the event processors, one per thread. */
|
||||
std::vector< Trick::EventProcessor * > event_processors ; /**< trick_io(**) */
|
||||
|
||||
|
@ -23,7 +23,11 @@
|
||||
|
||||
Trick::EventManager * the_em ;
|
||||
|
||||
Trick::EventManager::EventManager() { the_em = this ; }
|
||||
Trick::EventManager::EventManager() :
|
||||
active_events(NULL),
|
||||
num_active_events(0),
|
||||
num_allocated(0)
|
||||
{ the_em = this ; }
|
||||
|
||||
//Command to get the event object given the event's name
|
||||
Trick::Event * Trick::EventManager::get_event(std::string event_name) {
|
||||
@ -52,9 +56,14 @@ int Trick::EventManager::add_to_active_events(Trick::Event * in_event) {
|
||||
}
|
||||
num_active_events++;
|
||||
if (num_active_events == 1) {
|
||||
active_events = (Trick::Event **)TMM_declare_var_s("Trick::Event* [1]");
|
||||
} else {
|
||||
active_events = (Trick::Event **)TMM_resize_array_1d_a(active_events, num_active_events);
|
||||
active_events = (Trick::Event **)TMM_declare_var_s("Trick::Event* [100]");
|
||||
num_allocated = 100 ;
|
||||
} else if ( num_active_events >= num_allocated ) {
|
||||
num_allocated += 100 ;
|
||||
active_events = (Trick::Event **)TMM_resize_array_1d_a(active_events, num_allocated);
|
||||
for ( unsigned int ii = num_active_events ; ii < num_allocated ; ii++ ) {
|
||||
active_events[ii] = NULL ;
|
||||
}
|
||||
}
|
||||
active_events[num_active_events-1] = in_event ;
|
||||
return (0) ;
|
||||
@ -209,18 +218,18 @@ int Trick::EventManager::remove_event(Trick::Event * in_event) {
|
||||
active_events[jj - 1] = active_events[jj] ;
|
||||
}
|
||||
num_active_events-- ;
|
||||
if (num_active_events == 0) {
|
||||
TMM_delete_var_a(active_events);
|
||||
active_events = NULL;
|
||||
}
|
||||
else {
|
||||
active_events[num_active_events] = NULL ;
|
||||
}
|
||||
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_active_events == 0) {
|
||||
TMM_delete_var_a(active_events);
|
||||
active_events = NULL;
|
||||
}
|
||||
else {
|
||||
active_events = (Trick::Event **)TMM_resize_array_1d_a(active_events, num_active_events);
|
||||
}
|
||||
|
||||
if ( in_event->get_free_on_removal() ) {
|
||||
TMM_delete_var_a(in_event) ;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user