本文整理汇总了C++中MemPool::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ MemPool::reset方法的具体用法?C++ MemPool::reset怎么用?C++ MemPool::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemPool
的用法示例。
在下文中一共展示了MemPool::reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
// TestCase Group1:
MemPool objMemPool;
MemPool *pMemPool = &objMemPool;
int32_t nCount = 10;
char *pszArray = NEW_VEC(pMemPool, char, nCount);
int32_t *pnArray = NEW_VEC(pMemPool, int32_t, nCount);
float *pfArray = NEW_VEC(pMemPool, float, nCount);
for (int i = 0; i < nCount; i++) {
pszArray[i] = 'a' + i;
pnArray[i] = i;
pfArray[i] = 1.0 * i;
}
for (int i = 0; i < nCount; i++) {
fprintf(stdout, "pszArray[%d]:\t%c\n", i, pszArray[i]);
fprintf(stdout, "pnArray[%d]:\t%d\n", i, pnArray[i]);
fprintf(stdout, "pfArray[%d]:\t%f\n", i, pfArray[i]);
}
pMemPool->reset();
// TestCase Group2:
MemPool objMemPool2;
MemPool *pMemPool2 = &objMemPool2;
int32_t nCount2 = 10;
MyClass *pMyClass = NEW(pMemPool2, MyClass);
fprintf(stdout, "pMyClass:\t%d\n", pMyClass->getCount());
MyClass *pMyClass2 = NEW(pMemPool2, MyClass)(100);
fprintf(stdout, "pMyClass2:\t%d\n", pMyClass2->getCount());
MyClass *pMyClassArray = NEW_ARRAY(pMemPool2, MyClass, nCount2);
for (int i = 0; i < nCount2; i++) {
fprintf(stdout, "pMyClassArray[%d]:\t%d\n", i, pMyClassArray[i].getCount());
}
pMemPool2->reset();
// TestCase Group3:
MemPool objMemPool3;
MemPool *pMemPool3 = &objMemPool3;
MemMonitor memMonitor(pMemPool3, 1);
pMemPool3->setMonitor(&memMonitor);
memMonitor.enableException();
int32_t nCount3 = 1;
char *pszArray3 = NEW_VEC(pMemPool3, char, nCount3);
if (!pszArray3) {
printf("pszArray3 NEW_VEC Err!\n");
}
nCount3 = 1024;
int32_t *pnArray3 = NEW_VEC(pMemPool3, int32_t, nCount3);
if (!pnArray3) {
printf("pnArray3 NEW_VEC Err!\n");
}
float *pfArray3 = NEW_VEC(pMemPool3, float, nCount3);
if (!pfArray3) {
printf("pfArray3 NEW_VEC Err!\n");
}
for (int i = 0; i < nCount3; i++) {
pszArray3[i] = 'a' + i;
pnArray3[i] = i;
pfArray3[i] = 1.0 * i;
}
for (int i = 0; i < nCount3; i++) {
fprintf(stdout, "pszArray3[%d]:\t%c\n", i, pszArray3[i]);
fprintf(stdout, "pnArray3[%d]:\t%d\n", i, pnArray3[i]);
fprintf(stdout, "pfArray3[%d]:\t%f\n", i, pfArray3[i]);
}
pMemPool3->reset();
// TestCase Group4:
MemPool objMemPool4;
MemPool *pMemPool4 = &objMemPool4;
MemMonitor memMonitor4(pMemPool4, 1);
pMemPool4->setMonitor(&memMonitor4);
memMonitor4.enableException();
int32_t nCountsz4 = 1024;
char *pszArraysz4 = NEW_VEC(pMemPool4, char, nCountsz4);
if (!pszArraysz4) {
printf("pszArraysz4 is NULL\n");
}
MyClass *pMyClass4 = NEW(pMemPool4, MyClass);
if (!pMyClass4) {
printf("pMyClass4 is NULL\n");
}
fprintf(stdout, "pMyClass4:\t%d\n", pMyClass4->getCount());
int32_t nCountsz4_1 = 1024;
char *pszArraysz4_1 = NEW_VEC(pMemPool4, char, nCountsz4_1);
if (!pszArraysz4_1) {
printf("pszArraysz4_1 is NULL\n");
}
MyClass *pMyClass4_1 = NEW(pMemPool4, MyClass)(100);
if (!pMyClass4_1) {
printf("pMyClass4_1 is NULL\n");
}
fprintf(stdout, "pMyClass4_1:\t%d\n", pMyClass4_1->getCount());
int32_t nCountsz4_2 = 1024;
char *pszArraysz4_2 = NEW_VEC(pMemPool4, char, nCountsz4_2);
if (!pszArraysz4_2) {
printf("pszArraysz4_2 is NULL\n");
//.........这里部分代码省略.........
示例2: snprintf
int32_t IndexFieldInc::idx2Txt(idx_dict_t* pdict)
{
if(NULL == pdict) {
return 0;
}
char filename[PATH_MAX];
snprintf(filename, PATH_MAX, "%s/%s.txt", _idxPath, _fieldName);
FILE* fp = fopen(filename, "wb");
if(NULL == fp) {
return -1;
}
unsigned int pos = 0;
MemPool cMemPool;
idict_node_t* pNode = idx_dict_first(pdict, &pos);
DocIdManager* pDoc = DocIdManager::getInstance();
DocIdManager::DeleteMap* del = pDoc->getDeleteMap();
int maxNum = 0, num = 0;
DocListUnit* list = NULL;
while(pNode) {
IndexTerm* pIndexTerm = getTerm(&cMemPool, pNode->sign);
if(NULL == pIndexTerm) {
TERR("get %s %lu error\n", _fieldName, pNode->sign);
fclose(fp);
return -1;
}
const IndexTermInfo* pTermInfo = pIndexTerm->getTermInfo();
if(maxNum < pTermInfo->docNum) {
if(list) delete [] list;
maxNum = pTermInfo->docNum;
list = new DocListUnit[maxNum];
}
uint32_t docId;
if(pTermInfo->maxOccNum > 0) {
num = 0;
while((docId = pIndexTerm->next()) < INVALID_DOCID) {
if(del->isDel(docId)) continue;
int32_t count;
uint8_t* pocc = pIndexTerm->getOcc(count);
for(int32_t i = 0; i < count; i++, num++) {
list[num].doc_id = docId;
list[num].occ = pocc[i];
}
}
} else {
num = 0;
while((docId = pIndexTerm->next()) < INVALID_DOCID) {
if(del->isDel(docId)) continue;
list[num].doc_id = docId;
list[num++].occ = 0;
}
}
if(num > 0) {
fprintf(fp, "term:%lu docNum:%d\n", pNode->sign, num);
if(pTermInfo->maxOccNum > 0) {
for(int32_t i = 0; i < num; i++) {
fprintf(fp, "%lu(%u) ", pDoc->getNid(list[i].doc_id), list[i].occ);
}
} else {
for(int32_t i = 0; i < num; i++) {
fprintf(fp, "%lu ", pDoc->getNid(list[i].doc_id));
}
}
fprintf(fp, "\n");
}
cMemPool.reset();
pNode = idx_dict_next(pdict, &pos);
}
fclose(fp);
if (list) delete [] list;
return 0;
}