// file: tr_mm_new_1.cc
//
 
// isip include files
//
#include "train_memory_manager.h"
#include "train_memory_manager_constants.h"

#include <train_trace.h>

// method: new_trace_cc
//
// arguments: none
//
// return: a Train_Trace* pointer to a new trace
//
// this method outputs a new empty trace, and creates them whenever
// necessary
//
Train_Trace* Train_Memory_manager::new_trace_cc() {

  // if there are no free traces available, create a few
  //
  if (trace_count_d == (int_4)0) {
    grow_trace_cc();
  }

  // get a trace off the list
  //
  Train_Link_node* lnd = trace_list_d;
  trace_list_d = trace_list_d->get_next_cc();

  // adjust link params
  //
  lnd->set_next_cc((Train_Link_node*)NULL);
  lnd->set_prev_cc((Train_Link_node*)NULL);

  // get the trace here
  //
  Train_Trace* trace = (Train_Trace*)(lnd->get_item_cc());

  // return the link node to the free node list
  //
  delete_cc(lnd);

  // decrement free trace count
  //
  trace_count_d --;
  
  // return the trace and exit gracefully
  //
  return trace;
}
