Mercurial > hg > audiodb
comparison audioDB.cpp @ 173:42585bd03636 no-big-mmap
Don't use mmap() in database creation
author | mas01cr |
---|---|
date | Wed, 14 Nov 2007 15:57:15 +0000 |
parents | cdd441dcc9a8 |
children | 2826339b4e92 |
comparison
equal
deleted
inserted
replaced
172:a28690f14021 | 173:42585bd03636 |
---|---|
377 void audioDB::create(const char* dbName){ | 377 void audioDB::create(const char* dbName){ |
378 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) | 378 if ((dbfid = open (dbName, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) |
379 error("Can't create database file", dbName, "open"); | 379 error("Can't create database file", dbName, "open"); |
380 get_lock(dbfid, 1); | 380 get_lock(dbfid, 1); |
381 | 381 |
382 // go to the location corresponding to the last byte | |
383 if (lseek (dbfid, size - 1, SEEK_SET) == -1) | |
384 error("lseek error in db file", "", "lseek"); | |
385 | |
386 // write a dummy byte at the last location | |
387 if (write (dbfid, "", 1) != 1) | |
388 error("write error", "", "write"); | |
389 | |
390 // mmap the output file | 382 // mmap the output file |
391 if(verbosity) { | 383 if(verbosity) { |
392 cerr << "header size:" << O2_HEADERSIZE << endl; | 384 cerr << "header size:" << O2_HEADERSIZE << endl; |
393 } | 385 } |
394 if ((db = (char*) mmap(0, size, PROT_READ | PROT_WRITE, | |
395 MAP_SHARED, dbfid, 0)) == (caddr_t) -1) | |
396 error("mmap error for creating database", "", "mmap"); | |
397 | 386 |
398 dbH = new dbTableHeaderT(); | 387 dbH = new dbTableHeaderT(); |
399 assert(dbH); | 388 assert(dbH); |
400 | 389 |
401 unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE); | 390 unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE); |
412 dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles, 8); | 401 dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles, 8); |
413 dbH->l2normTableOffset = ALIGN_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8); | 402 dbH->l2normTableOffset = ALIGN_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8); |
414 dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8); | 403 dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8); |
415 dbH->dbSize = size; | 404 dbH->dbSize = size; |
416 | 405 |
417 memcpy (db, dbH, O2_HEADERSIZE); | 406 write(dbfid, dbH, O2_HEADERSIZE); |
407 | |
408 // go to the location corresponding to the last byte | |
409 if (lseek (dbfid, size - 1, SEEK_SET) == -1) | |
410 error("lseek error in db file", "", "lseek"); | |
411 | |
412 // write a dummy byte at the last location | |
413 if (write (dbfid, "", 1) != 1) | |
414 error("write error", "", "write"); | |
415 | |
418 if(verbosity) { | 416 if(verbosity) { |
419 cerr << COM_CREATE << " " << dbName << endl; | 417 cerr << COM_CREATE << " " << dbName << endl; |
420 } | 418 } |
421 } | 419 } |
422 | 420 |