Unhandled exception access voilation reading location error while implementing linked list in c++
Revision 3
I have the following function :
void each_user_specifications :: algorithm_enqueue_stage (single_connection_per_user_queue *satq, int num_satq)
{
int k=0;
double bandwidth_allocated_to_each_user;
double pkt_size, pkt_arrival_time;
packet_with_attributes *temp1, *temp2;
each_user_specifications ssq;
default_random_engine t(time (0));
for (int i=0; i< num_satq; i++)
{
for (int j=0; j<2; j++)
{
uniform_real_distribution <> pkts_size(0, 600);
pkt_size = pkts_size (t);
uniform_real_distribution <> pkts_interarrival_times(0.001, 0.005);
pkt_arrival_time = pkts_interarrival_times (t);
(satq+i)->head = enqueue_the_packet (pkt_size, pkt_arrival_time);
}
temp1 = (satq+i)->head;
cout <<"\n\nGenerated packets for class "<<(satq+i)->cos<<" are :\n\n";
while (temp1 != NULL)
{
cout <<temp1->new_packet_size<<" ' "<<temp1->new_packet_arrival_time<<" ";
temp1 = temp1->new_packet;
}
}
}
I am calling this function from another function in the following way:
void each_user_specifications ::main_algorithm (each_user_specifications u[], int obj_array_size, double sched_cycle_system_bandwidth)
{
static int run_count_main = 0;
each_user_specifications user[45];
int sno_counter;
single_connection_per_user_queue *init_satq;
unsigned int token_bank_capacity = 0;
int tot_queues=0, num_leadq=0, num_satq=0, num_lagq=0;
sno_counter = obj_array_size;
for (int i=0; i<obj_array_size; i++)
user[i] = u[i];
run_count_main ++;
if (run_count_main <= 1)
{
init_satq = algorithm_each_user_parameters_initialization_stage (user, sno_counter, sched_cycle_system_bandwidth, token_bank_capacity, tot_queues);
algorithm_enqueue_stage (init_satq, tot_queues);
algorithm_dequeue_stage (init_satq, tot_queues);
algorithm_post_scheduling_stage (init_satq, tot_queues, num_leadq, num_satq, num_lagq);
}
system ("PAUSE");
}
But, I am getting Unhandled exception access voilation reading location error on calling that function. But, I am not getting any error when I am calling
algorithm_enqueue_stage () from algorithm_each_user_parameters_initialization_stage() - i.e. I am directly passing satq to algorithm_enqueue_stage from algorithm_each_user_parameters_initilization_stage ().
A frequent reply is really appreciated...., it's an urgency for me. Thanks in Advance.
This is the function definition of my parameters_initialization_stage () :
single_connection_per_user_queue *each_user_specifications :: algorithm_each_user_parameters_initialization_stage (each_user_specifications u[], int obj_array_size, double sched_cycle_system_bandwidth, unsigned int &token_bank_capacity, int &tot_queues)
{
int k = 0, j=0,num_users = 0;
double total_input_bandwidth_allocated = 0.0;
int no_leadq = 0, no_satq = 0, no_lagq = 0;
single_connection_per_user_queue satq[75];
int remaining_users_counter= 0;
int inap_flag = 0;
while (total_input_bandwidth_allocated < sched_cycle_system_bandwidth)
{
if ((total_input_bandwidth_allocated + u[k].total_STR) >= sched_cycle_system_bandwidth)
break;
total_input_bandwidth_allocated += u[k].total_STR;
for (int i=0; i< u[k].num_CoS; i++)
{
u[k].q[i].token_bucket_min_depth = u[k].q[i].MRTR * 1000 * 5/8;
u[k].q[i].token_bucket_avg_depth = u[k].q[i].STR * 1000 * 5/8;
u[k].q[i].token_bucket_max_depth = u[k].q[i].MSTR * 1000 * 5/8;
u[k].q[i].avg_tokens_lead_or_lagged = u[k].q[i].token_bucket_avg_depth;
u[k].q[i].tokens_generated = u[k].q[i].token_bucket_avg_depth;
u[k].q[i].head = NULL;
satq[tot_queues] = u[k].q[i];
//cout <<satq[tot_queues].token_bucket_min_depth<<"\t"<<satq[tot_queues].token_bucket_max_depth<<"\n\n";
//system ("PAUSE");
cout <<u[k].q[i].tokens_generated<<" tokens are generated for class "<<u[k].q[i].cos<<" of user "<<(k+1)<<"\n\n";
tot_queues ++;
}
/*for (int l=0; l< u[k].num_CoS; l++)
{
if ((u[k].q[l].token_bucket_min_depth == 0 && u[k].q[l].token_bucket_max_depth == u[k].q[l].token_bucket_min_depth) || (u[k].q[l].token_bucket_max_depth - u[k].q[l].token_bucket_min_depth <= 1))
{
inap_flag = 1;
break;
}
}*/
//if (inap_flag == 0)
//{
k++;
}
remaining_users_counter = k;
while (remaining_users_counter < obj_array_size)
{
for (int j=0; j< u[remaining_users_counter].num_CoS; j++)
{
u[remaining_users_counter].q[j].token_bucket_min_depth = 0;
u[remaining_users_counter].q[j].token_bucket_avg_depth = 0;
u[remaining_users_counter].q[j].token_bucket_max_depth = 0;
u[k].q[j].avg_tokens_lead_or_lagged = u[k].q[j].token_bucket_avg_depth;
u[remaining_users_counter].q[j].tokens_generated = u[k].q[j].token_bucket_avg_depth;
u[k].q[j].head = NULL;
//satq[tot_queues] = u[k].q[j];
}
remaining_users_counter++;
}
token_bank_capacity = (sched_cycle_system_bandwidth - total_input_bandwidth_allocated) * 5 * 1000;
cout <<tot_queues<<" queues are generated for "<<k<<" users\n\n";
system ("PAUSE");
//algorithm_enqueue_stage (satq, tot_queues);
//system ("PAUSE");
return satq;
//algorithm_enqueue_stage (satq, tot_queues);
//if (((k+1) - last_sched_cycle_users) > 0)
//{
//for (int i=last_sched_cycle_users-1; i<=k; i++)
//{
//for (int j=0; j< u[i].num_CoS; j++)
//u[i].q[j].avg_tokens_lead_or_lagged = u[i].q[j].token_bucket_avg_depth;
//}
//}
//cout <<"\nTHE NUMBER OF USERS ACOMODATED IN THE CURRENT SCHEDULING CYCLE ARE "<<(k+1)<<"\n\n";
//cout <<"TOTAL BANDWIDTH ALLOCATED IS "<<total_input_bandwidth_allocated<<" Mbps\n\n";
//system ("PAUSE");
//cout <<"THE REMAINING BANDWIDTH CONTAINED IN TOKEN BANK IS "<<(sched_cycle_system_bandwidth - total_input_bandwidth_allocated)<<" Mbps\n\n";
//system ("PAUSE"); */
//return k;
}
Posted 21-Sep-12 2:13am
by
wirelesscomm2k12.