108 Block(
int size,
void (*err_function)(
char *) = NULL) { first = last = NULL; block_size = size; error_function = err_function; }
111 ~Block() {
while (first) { block *next = first -> next;
delete first; first = next; } }
120 if (!last || last->current + num > last->last)
122 if (last && last->next) last = last -> next;
125 block *next = (block *)
new char [
sizeof(block) + (block_size-1)*
sizeof(Type)];
126 if (!next) { exit(1); }
127 if (last) last -> next = next;
130 last -> current = & ( last -> data[0] );
131 last -> last = last -> current + block_size;
137 last -> current += num;
144 for (scan_current_block=first; scan_current_block; scan_current_block = scan_current_block->next)
146 scan_current_data = & ( scan_current_block -> data[0] );
147 if (scan_current_data < scan_current_block -> current)
return scan_current_data ++;
157 while (scan_current_data >= scan_current_block -> current)
159 scan_current_block = scan_current_block -> next;
160 if (!scan_current_block)
return NULL;
161 scan_current_data = & ( scan_current_block -> data[0] );
163 return scan_current_data ++;
171 for (b=first; ; b=b->next)
173 b -> current = & ( b -> data[0] );
174 if (b == last)
break;
183 typedef struct block_st
185 Type *current, *last;
186 struct block_st *next;
194 block *scan_current_block;
195 Type *scan_current_data;
197 void (*error_function)(
char *);
211 DBlock(
int size,
void (*err_function)(
char *) = NULL) { first = NULL; first_free = NULL; block_size = size; error_function = err_function; }
214 ~DBlock() {
while (first) { block *next = first -> next;
delete first; first = next; } }
224 first = (block *)
new char [
sizeof(block) + (block_size-1)*
sizeof(block_item)];
225 if (!first) { exit(1); }
226 first_free = & (first -> data[0] );
227 for (item=first_free; item<first_free+block_size-1; item++)
228 item -> next_free = item + 1;
229 item -> next_free = NULL;
230 first -> next = next;
234 first_free = item -> next_free;
235 return (Type *) item;
241 ((block_item *) t) -> next_free = first_free;
242 first_free = (block_item *) t;
249 typedef union block_item_st
252 block_item_st *next_free;
255 typedef struct block_st
257 struct block_st *next;
263 block_item *first_free;
265 void (*error_function)(
char *);
Block(int size, void(*err_function)(char *)=NULL)
DBlock(int size, void(*err_function)(char *)=NULL)