// file: mm_grow_7.cc
//
 
// isip include files
//
#include "memory_manager.h"
#include "memory_manager_constants.h"

#include <instance.h>

// method: grow_instance_cc
//
// arguments: none
//
// return: a logical_1 indicating success
//
// this method grows the number of empty instance nodes by the instance
// grow size
//
logical_1 Memory_manager::grow_instance_cc() {

  // create new empty instances
  //
  Instance** inst = new Instance*[instance_grow_size_d];
  Link_node* lnd = (Link_node*)NULL;
  
  // insert the instances into a list
  //
  for (int_4 i = 0; i < instance_grow_size_d; i++) {
    lnd = new_node_cc();
    inst[i] = new Instance();
    lnd->set_item_cc((void_p)inst[i]);
    if ((i == (int_4)0) && (instance_count_d == (int_4)0)) {
      instance_list_d = lnd;
    }
    else {
      instance_list_d->insert_cc(lnd);
    }
  }
  
  // update the count of free instances
  //
  instance_count_d += instance_grow_size_d;
  num_instance_d += instance_grow_size_d;

  // free pointer memory since the objects will be deleted seperately
  //
  delete [] inst;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
