예제 #1
0
 const char *sgStrHandleCenter::getString(const char *str)
 {
     if(!str)
         return sgStrHandle::EmptyString.getStr();
     
     std::string stdstr = str;
     StringMap::iterator it = mStringMap.find(stdstr);
     if(it != mStringMap.end())
         return it->second.getStr();
     
     size_t len = stdstr.size() + 1; // '\0'
     
     assert(mLatestPool);
     char *ptr = mLatestPool->allocate(len);
     
     if(!ptr)
     {
         for(size_t i=0; i<mPoolVec.size(); ++i)
         {
             ptr = mPoolVec[i].allocate(len);
             if(ptr)
             {
                 mLatestPool = &(mPoolVec[i]);
                 break;
             }
         }
         
         if(!ptr)
         {
             mLatestPool = createNewPool();
             ptr = mLatestPool->allocate(len);
         }
     }
     
     if(ptr)
     {
         strncpy(ptr, str, len-1);
         ptr[len-1] = '\0';
         sgStrHandle strHandle;
         strHandle.mStr = ptr;
         mStringMap.insert(std::make_pair(stdstr, strHandle));
         
         mStringMemSize += len;
         
         return ptr;
     }
     
     return sgStrHandle::EmptyString.getStr();
 }
예제 #2
0
파일: pooltest.c 프로젝트: LinHu2016/omr
int32_t
createAndVerifyPool(OMRPortLibrary *portLib, PoolInputData *input)
{
	J9Pool *pool = createNewPool(portLib, input);
	int32_t elementCount = 0;
	int32_t rc = 0;

	if (NULL == pool) {
		return -1;
	}
	elementCount = testPoolNewElement(portLib, input, pool);
	if (elementCount < 0) {
		return elementCount;
	}
	rc = testPoolWalkFunctions(portLib, input, pool, elementCount);
	if (0 != rc) {
		return rc;
	}
	/* Clear the pools, and test new, walk, and remove again. */
	rc = testPoolClear(portLib, pool);
	if (0 != rc) {
		return rc;
	}
	elementCount = testPoolNewElement(portLib, input, pool);
	if (elementCount < 0) {
		return elementCount;
	}
	rc = testPoolWalkFunctions(portLib, input, pool, elementCount);
	if (0 != rc) {
		return rc;
	}
	rc = testPoolRemoveElement(portLib, pool);
	if (0 != rc) {
		return rc;
	}
	pool_kill(pool);

	return 0;
}
예제 #3
0
int main(int argc, char *argv[])
{
    FILE *fp;
    int i = 0;
    char line[MAX_LAST_NAME_SIZE];
    struct timespec start, end;
    double cpu_time1, cpu_time2;

    /* check file opening */
    fp = fopen(DICT_FILE, "r");
    if (fp == NULL) {
        printf("cannot open the file\n");
        return -1;
    }

    /* build the entry */
    //hashTable* ht = createHashTable(45577);
    pool* p = createNewPool();
    entry *pHead, *e;
    pHead = (entry *) malloc(sizeof(entry));
    printf("size of entry : %lu bytes\n", sizeof(entry));
    e = pHead;
    e->pNext = NULL;

#if defined(__GNUC__)
    __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
    clock_gettime(CLOCK_REALTIME, &start);
    while (fgets(line, sizeof(line), fp)) {
        while (line[i] != '\0')
            i++;
        line[i - 1] = '\0';
        i = 0;
        e = poolAppend(line, e , p);
        ///hashAppend(line , ht , p );
    }
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time1 = diff_in_second(start, end);

    /* close file as soon as possible */
    fclose(fp);

    e = pHead;

    /* the givn last name to find */
    char input[MAX_LAST_NAME_SIZE] = "zyxel";
    e = pHead;

    assert(findName(input , e ) &&
           "Did you implement findName() in " IMPL "?");
    assert(0 == strcmp(findName(input ,e )->lastName, "zyxel"));

#if defined(__GNUC__)
    __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
    /* compute the execution time */
    clock_gettime(CLOCK_REALTIME, &start);
    findName(input, e);
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time2 = diff_in_second(start, end);

    FILE *output;
#if defined(OPT)
    output = fopen("pool.txt", "a");
#else
    output = fopen("orig.txt", "a");
#endif
    fprintf(output, "append() findName() %lf %lf\n", cpu_time1, cpu_time2);
    fclose(output);

    printf("execution time of append() : %lf sec\n", cpu_time1);
    printf("execution time of findName() : %lf sec\n", cpu_time2);

    if (pHead->pNext) free(pHead->pNext);
    free(pHead);

    return 0;
}
예제 #4
0
 sgStrHandleCenter::sgStrHandleCenter(void)
 {
     mStringMemSize = 0;
     mLatestPool = createNewPool();
 }