#include<stdio.h>
#include<stdlib.h>
typedef struct _anyT {
int val;
} anyT;
#define UNITS 10
typedef union _data_block {
union _data_block *next;
anyT the_type;
} data_block;
static data_block *free_list = NULL;
static void moremem(void) {
int i;
data_block *more = calloc(sizeof(data_block),UNITS);
for(i = 0; i < UNITS; i++) {
more[i].next = free_list;
free_list = more + i;
}
}
anyT *allocanyT(void) {
data_block *current;
if(free_list == NULL) {
moremem();
return allocanyT();
}
current = free_list;
free_list = free_list->next;
return &(current->the_type);
}
void freeanyT(anyT *x)
{
((data_block *)x)->next = free_list;
free_list = (data_block *)x;
}
void clearpool() {
data_block *head;
anyT* cur;
for(head=free_list;head;head=free_list) {
free_list=free_list->next;
cur=(anyT*)&head->the_type;
free(cur);
}
}
Как показано выше, функция clearpool () фактически не работает !!! мне интересно
если какой-либо эксперт может объяснить мне, почему и помочь мне решить это. заранее спасибо.
С наилучшими пожеланиями,