Exemple #1
0
int StrCache_Pop()
{
    int i;
    if(strcache_size == 0)
    {
        StrCache_Init();
    }
    if(strcache_top < 0) // realloc
    {
        __reallocto(strcache, strcache_size, strcache_size + STRCACHE_INC);
        __reallocto(strcache_index, strcache_size, strcache_size + STRCACHE_INC);
        for(i = 0; i < STRCACHE_INC; i++)
        {
            strcache_index[i] = strcache_size + i;
            strcache[i + strcache_size].str = malloc(sizeof(CHAR) * (MAX_STR_VAR_LEN + 1));
            strcache[i + strcache_size].str[0] = 0;
            strcache[i + strcache_size].len = MAX_STR_VAR_LEN;
        }

        //printf("debug: dumping string cache....\n");
        //for(i=0; i<strcache_size; i++)
        //	printf("\t\"%s\"  %d\n", strcache[i].str, strcache[i].ref);

        strcache_size += STRCACHE_INC;
        strcache_top += STRCACHE_INC;

        //printf("debug: string cache resized to %d \n", strcache_size);
    }
    i = strcache_index[strcache_top--];
    strcache[i].ref = 1;
    return i;
}
Exemple #2
0
int StrCache_Pop() {
	CHAR **temp;
	int *tempi;
	int i;
	if(strcache_size == 0) {
		StrCache_Init();
	}
	if(strcache_top < 0)	// realloc
	{
		temp = malloc(sizeof(CHAR *) * (strcache_size + STRCACHE_INC));
		//if(!temp) shutdown(1, "out of memory");
		for(i = strcache_size; i < strcache_size + STRCACHE_INC; i++) {
			temp[i] = malloc((MAX_STR_VAR_LEN + 1) * sizeof(CHAR));
			//if(!strcache[i]) shutdown(1, "out of memory");
			temp[i][0] = 0;
		}
		for(i = 0; i < strcache_size; i++) {
			temp[i] = strcache[i];
		}
		free(strcache);
		strcache = temp;
		tempi = malloc(sizeof(int) * (strcache_size + STRCACHE_INC));
		//if(!tempi) shutdown(1, "out of memory");
		for(i = 0; i < STRCACHE_INC; i++) {
			tempi[i] = strcache_size + i;
		}
		free(strcache_index);
		strcache_index = tempi;
		strcache_size += STRCACHE_INC;
		strcache_top += STRCACHE_INC;
	}
	return strcache_index[strcache_top--];
}