本文整理汇总了C++中FileSystem::getPageCount方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::getPageCount方法的具体用法?C++ FileSystem::getPageCount怎么用?C++ FileSystem::getPageCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem::getPageCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
if (argc > 5) {
fprintf(stderr, "Syntax: filesystem DATA_FILE PAGE_SIZE PAGE_COUNT TEST_DATA\n\n");
fprintf(stderr, "Creates a filesystem inside DATAFILE with given parameters and tests it using\n");
fprintf(stderr, "Data taken from the file TEST_DATA.\n\n");
return 1;
}
argv[1] = "../temp/data_file";
argv[2] = "4096";
argv[3] = "1024";
argv[4] = "../temp/test_data";
char *fileName = argv[1];
int pageSize = atoi(argv[2]);
int pageCount = atoi(argv[3]);
char *testData = argv[4];
FileSystem *fs = new FileSystem(fileName, pageSize, pageCount);
if (!fs->isActive()) {
fprintf(stderr, "Could not create filesystem.\n");
return 1;
}
int inputFile = open(testData, O_RDONLY);
File **f = new File*[256];
for (int i = 0; i < TEST_FILES; i++) {
f[i] = new File(fs);
printf("new handle: %i. fileCount: %i\n", f[i]->getHandle(), fs->getFileCount());
}
f[4]->deleteFile();
delete f[4];
f[4] = new File(fs);
printf("new handle: %i. fileCount: %i\n", f[4]->getHandle(), fs->getFileCount());
int cnt = 0;
char buffer[373];
int inputFileSize = 0;
while (true) {
int size = forced_read(inputFile, buffer, sizeof(buffer));
if (size == 0)
break;
for (int i = 0; i < TEST_FILES; i++)
f[i]->write(size, buffer);
inputFileSize += size;
}
char *inputData = (char*)malloc(inputFileSize);
lseek(inputFile, 0, SEEK_SET);
forced_read(inputFile, inputData, inputFileSize);
printf("Total pages: %i. Used: %i.\n", fs->getPageCount(), fs->getUsedPageCount());
int64_t a, b, c, d;
fs->getCacheEfficiency(&a, &b, &c, &d);
printf("Cache efficiency: %i/%i reads, %i/%i writes.\n",
(int)b, (int)a, (int)d, (int)c);
for (int i = 0; i < TEST_FILES; i++) {
lseek(inputFile, 0, SEEK_SET);
f[i]->seek(0);
printf("f[%i]->getSize() = %i\n", i, f[i]->getSize());
for (int j = 0; j < f[i]->getSize(); j++) {
char c;
f[i]->read(1, &c);
if (c != inputData[j])
fprintf(stderr, "ERROR!\n");
}
printf(" File %i ok.\n", i);
}
printf("Before closing: %i %i %i.\n", fs->getPageSize(), fs->getPageCount(), fs->getFileCount());
// close files and close filesystem
for (int i = 0; i < TEST_FILES; i++)
delete f[i];
delete fs;
/*
fs = new FileSystem(fileName);
if (fs->defrag() == FILESYSTEM_ERROR) {
fprintf(stderr, "defrag() returns error code.\n");
return 1;
}
delete fs;
*/
for (int loop = 0; loop < 256; loop++) {
fs = new FileSystem(fileName);
printf("After reopening: %i %i %i.\n", fs->getPageSize(), fs->getPageCount(), fs->getFileCount());
for (int i = 0; i < TEST_FILES; i++) {
lseek(inputFile, 0, SEEK_SET);
f[i] = new File(fs, i, false);
f[i]->seek(0);
for (int j = 0; j < f[i]->getSize(); j++) {
char c;
f[i]->read(1, &c);
if (c != inputData[j])
fprintf(stderr, "ERROR!\n");
}
delete f[i];
}
delete fs;
//.........这里部分代码省略.........