mmapÊÇlinuxϵÄCreateFileMapping£¬ÓÃÀ´Ó³É䲢ͬ²½Îļþ¡£
ÕâÑùµÄ»°£¬±ÈÈçÎÒ×Ô¶¨ÒåÒ»ÖÖÎļþ¸ñʽ£¬°ÑËüдÈëµ½ÎļþÖУ¬ÏÖÔÚÏëÐÞ¸ÄÆäÖеÄÖµ£¬¾Í¿ÉÒÔÓÃÕâ¸öº¯Êý£¬°ÑÎļþÓ³Éäµ½ÄÚ´æÖÐ
È»ºóÓòÙ×÷Êý×éµÄ·½Ê½£¬À´½øÐÐÎļþµÄͬ²½¡£Èç¹û²»ÓÃÕâ¸öº¯Êý¾ÍµÃ£º
1¡¢¶¨ÒåÒ»¸ö½á¹¹Ìå
2¡¢¶¨Òå½á¹¹ÌåÊý×é
3¡¢¶ÁÈ¡Îļþ£¨w+£©
4¡¢ÐÞ¸ÄÎļþ
5¡¢Ð´»ØÎļþ
Èç¹ûÓÃÕâ¸öº¯Êý£¬¾Í²»ÐèÒªÄÇôÂé·³ÁË£º
1¡¢¶¨Òå½á¹¹Ìå
2¡¢¶¨Òå½á¹¹ÌåÖ¸Õë
3¡¢´ò¿ªÎļþ£¬½«Îļþ¾ä±ú´«µÝ¸ømmap½øÐÐÓ³É䣬·µ»ØµÄÊǽṹÌåÊý×é
4¡¢Ð޸IJ¢Ð´»Ø
¾ßÌåµÄ²îÒìÌåÏÖÔÚ»ØдÉÏ¡£
Ìù¶Î´úÂ룬Àý×ÓÊÇ¡¶linux³ÌÐòÉè¼Æ µÚÈý°æ¡·ÖиøµÄ¡£
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
typedef struct
{
int integer;
char string[24];
} RECORD;
#define NRECORDS 100
#define FILENAME ("records.dat")
int main()
{
RECORD record, *mapped;
int i,f;
FILE *fp;
fp = fopen(FILENAME,"w+");
if(!fp)
{
perror("opern file error");
return EXIT_FAILURE;
}
for(i = 0; i < NRECORDS; i++)
{
bzero(&record,sizeof(record));
record.integer = i;
sprintf(record.string,"RECORD-%d",i);
fwrite(&record,sizeof(record),1,fp);
}
fclose(fp);
fp = fopen(FILENAME,"r+");
fseek(fp,43*sizeof(record),SEEK_SET);
fread(&record,sizeof(record),1,fp);
record.integer = 143;
sprintf(record.string,"RECORD-%d",record.integer);
fseek(fp,43*sizeof(record),SEEK_SET);
fwrite(&record,sizeof(record),1,fp);
fclose(fp);
//´ò¿ªÎļþ,¿É¶Á¿Éд
f = open(FILENAME,O_RDWR);
//ÒÔ¹²Ïíģʽmmap£¬Ïê¼ûman mmap
mapped = (RECORD *)mmap(0,NRECORDS * sizeof(record),
PROT_READ | PROT_WRITE,MAP_SHARED,f,0);
//¸Ä±äÆäÖеÄÖµ£¬×Ö·û´®ºÍÊýÖµ
mapped[43].integer = 243;
sprintf(mapped[43].string,"RECORD-%d",mapped[43].integer);
//д»ØÎļþ£¬×îºóÒ»¸ö²ÎÊýÖ¸¶¨ÁËͬ²½¡¢Òì²½¡¢»Ø´«
msync((void *)mapped,NRECORDS * sizeof(record),MS_ASYNC)
http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html
Sunday, May 10, 2009
Hadoop should target C++/LLVM, not Java (because of watts)
< type="text/javascript">
digg_url="http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html";
Over the years, ......
ÎÊÌâÃèÊö£ºÐ´Ò»¸öº¯Êý£¬½ÓÊÜÒ»¸öÕûÊý£¨¼Ù¶¨ÓÃint±íʾ£©£¬Êä³ö¸ÃÕûÊýµÄ×Ö·û´®ÐÎʽ¡£²ÉÓÃÈçϺ¯ÊýÔÐÍ£º
void itoa ( int val, buf* );
ÕâÀï¼Ù¶¨buf×ã¹»´óÒÔÈÝÄÉÈκÎintÀàÐÍÊýÖµµÄ×Ö·û´®¡£
Õâ¸öÎÊÌ⣬³õ¿´ºÃÏñûÓÐʲôÄѶȡ£Èç¹ûÊÇ0£¬¾ÍÖ±½ÓÊä³ö'0'£»Èç¹ûÊÇÕýÊý£¬¾Íͨ¹ýÈ¡Ä£(%)ºÍÇóÉÌ(/)ÔËËã¿ÉÒÔÖðλȡµÃ¸ÃÕûÊýµÄÊý×Ö£¬²¢° ......