#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
uint16_t* rule_id_list = NULL;
uint16_t unused_rule_id_position = 0;
typedef struct
{
int a;
int b;
}abc_t;
abc_t* abc = NULL;
void init_rule_id()
{
abc_t* a = malloc(sizeof(abc_t) * 1000);
rule_id_list = malloc(sizeof(uint16_t) * 16000);
if (rule_id_list != NULL)
{
memset(rule_id_list, 0, sizeof(uint16_t) * 16000);
}
else
{
return;
}
int i = 0;
for (i = 0; i < 15999; i++)
{
rule_id_list[i] = i + 1;
}
}
uint16_t get_rule_id_position()
{
return unused_rule_id_position++;
}
void revert_rule_id(uint16_t rule_id_position)
{
unused_rule_id_position--;
uint16_t temp = 0;
temp = rule_id_list[unused_rule_id_position];
rule_id_list[unused_rule_id_position] = rule_id_list[rule_id_position];
rule_id_list[rule_id_position] = temp;
return;
}
void main()
{
init_rule_id();
uint16_t position1 = 0;
uint16_t position2 = 0;
uint16_t position3 = 0;
uint16_t position4 = 0;
uint16_t position5 = 0;
position1 = get_rule_id_position();
position2 = get_rule_id_position();
position3 = get_rule_id_position();
position4 = get_rule_id_position();
position5 = get_rule_id_position();
printf("position1 : %d \n", position1);
printf("position2 : %d \n", position2);
printf("position3 : %d \n", position3);
printf("position4 : %d \n", position4);
printf("position5 : %d \n", position5);
revert_rule_id(position4);
revert_rule_id(position2);
position4 = get_rule_id_position();
printf("position4 : %d \n", position4);
revert_rule_id(position4);
position2 = get_rule_id_position();
printf("position2 : %d \n", position2);
abc = malloc(sizeof(abc_t));
return;
}
浙公网安备 33010602011771号