void FreeAll(){ int idx; for (idx=0; idx<MaxNofElems; idx++){ if (arr[idx].ptr!=NULL) FreeElem(idx); } /* for */ } /* FreeAll */
void test1(void) { int i; assert(MAX >= 100); InitFMem(BasicAlloc, BasicFree, NULL, NULL); memset(a, 0, sizeof(a)); FAlloc(0); FFree(0); for (i = 0; i < MAX-50; i++) { AddElem(i, rand() % 50 + 1); } for (i = MAX-50; i < MAX; i++) { AddElem(i, rand() % 10 + 253); } for (i = 0; i < MAX; i++) { FreeElem(i); } for (i = 0; i < 10000; i++) { if (rand() % 2 && numInA < MAX) { AddRandElem(rand() % 20 + 1); } else if (numInA > 0) { FreeRandElem(); } } FreeAllElems(); AddRandElem(20); AddRandElem(40); AddRandElem(255); AddRandElem(256); FiniFMem(FMEM_CHECK); assert(g_memUsed == 0); printf("Test 1 -- Success.\n"); printMemStats(); }
void FreeAllElems() { int i; for (i = 0; i < MAX; i++) { if (a[i].ptr != NULL) { FreeElem(i); } } }
void FreeRandElem(void) { int i = rand() % MAX; int j = i; while (a[j].ptr == NULL) { j = (j + 1) % MAX; assert(j != i); } FreeElem(j); }
void StressTest(){ unsigned ActionCount = 0; int idx; while (1){ ActionCount++; if (ActionCount%(32768)==0){ printf("\n%i\n",ActionCount); PrintInfo(); TestElems(); FreeAll(); /*<<<<<<<<<<<<<<< PrintInfo(); >>>>>>>>>>>>>>>*/ } /* if */ idx = (int)(random()%MaxNofElems); if (arr[idx].ptr!=NULL){ FreeElem(idx); } /* if */ AllocElem(idx); } /* while */ } /* StressTest */