48 #include <sphinxbase/prim_type.h> 49 #include <sphinxbase/err.h> 50 #include <sphinxbase/ckd_alloc.h> 53 #include "blkarray_list.h" 56 #define BLKARRAY_DEFAULT_MAXBLKS 16380 57 #define BLKARRAY_DEFAULT_BLKSIZE 16380 61 _blkarray_list_init(int32 maxblks, int32 blksize)
65 if ((maxblks <= 0) || (blksize <= 0)) {
66 E_ERROR(
"Cannot allocate %dx%d blkarray\n", maxblks, blksize);
71 bl->ptr = (
void ***) ckd_calloc(maxblks,
sizeof(
void **));
72 bl->maxblks = maxblks;
73 bl->blksize = blksize;
76 bl->cur_row_free = blksize;
83 blkarray_list_init(
void)
85 return _blkarray_list_init(BLKARRAY_DEFAULT_MAXBLKS,
86 BLKARRAY_DEFAULT_BLKSIZE);
92 blkarray_list_reset(bl);
105 if (bl->cur_row_free >= bl->blksize) {
109 if (bl->cur_row >= bl->maxblks) {
110 E_ERROR(
"Block array (%dx%d) exhausted\n",
111 bl->maxblks, bl->blksize);
117 assert(bl->ptr[bl->cur_row] == NULL);
118 bl->ptr[bl->cur_row] = (
void **) ckd_malloc(bl->blksize *
121 bl->cur_row_free = 0;
124 bl->ptr[bl->cur_row][bl->cur_row_free] = data;
125 (bl->cur_row_free)++;
127 id = (bl->n_valid)++;
140 for (i = 0; i < bl->cur_row; i++) {
141 for (j = 0; j < bl->blksize; j++)
142 ckd_free(bl->ptr[i][j]);
144 ckd_free(bl->ptr[i]);
147 if (i == bl->cur_row) {
148 for (j = 0; j < bl->cur_row_free; j++)
149 ckd_free(bl->ptr[i][j]);
151 ckd_free(bl->ptr[i]);
157 bl->cur_row_free = bl->blksize;