Mercurial > hg > Game > Cerium
changeset 2004:8aff72ad65de draft
restore fix_byte
author | masa |
---|---|
date | Tue, 13 May 2014 01:46:48 +0900 |
parents | 7dc90c83a787 |
children | 4d1bc8cd3a62 |
files | example/word_count/main.cc |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/example/word_count/main.cc Mon May 05 22:11:49 2014 +0900 +++ b/example/word_count/main.cc Tue May 13 01:46:48 2014 +0900 @@ -46,6 +46,15 @@ off_t size; } st_mmap_t; +/*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ +static int +fix_byte(int size,int fix_byte_size) +{ + size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; + + return size; +} + static void my_read(char *filename, WordCount *w, TaskManager *manager) { @@ -95,8 +104,10 @@ fprintf(stderr,"can't fstat %s\n",filename); } + st_mmap.size = fix_byte(sb.st_size,4096); + //madvise(w->file_mmap, w->read_filesize, POSIX_MADV_NORMAL); - w->file_mmap = (char*)mmap(NULL,w->read_filesize,PROT_WRITE|PROT_READ,map,fd,(off_t)0); + w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_WRITE|PROT_READ,map,fd,(off_t)0); if (st_mmap.file_mmap == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n");