C/C++ÐÞ¸ÄÎı¾Îļþ
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, ......
·ÃÎÊNand FlashʱÐèÒªÏÈ·¢³öÃüÁȻºó·¢³öµØÖ·ÐòÁУ¬×îºó¶Á/дÊý¾Ý£»
ÐèҪʹÓø÷¸öÐźÅÀ´·Ö±æÃüÁî¡¢µØÖ·¡¢Êý¾Ý£»
S3C2410 µÄNand Flash¿ØÖÆÆ÷ ÌṩÁËÏà¹Ø¼Ä´æÆ÷À´¼ò»¯ÕâЩ²Ù×÷£º
& ......
µÚ7Õ ÄÚ´æ¹ÜÀí
»¶Ó½øÈëÄÚ´æÕâƬÀ×Çø¡£Î°´óµÄBill Gates Ôø¾Ê§ÑÔ£º
640K ought to be enough for everybody
— Bill Gates 1981
³ÌÐòÔ±ÃǾ³£±àдÄÚ´æ¹ÜÀí³ÌÐò£¬ÍùÍùÌáÐĵõµ¨¡£Èç¹û²»Ïë´¥À×£¬Î¨Ò»µÄ½â¾ö°ì·¨¾ÍÊÇ·¢ÏÖËùÓÐDZ·üµÄµØÀײ¢ÇÒÅųýËüÃÇ£¬¶ãÊǶ㲻Á˵ġ£±¾ÕµÄÄÚÈݱÈÒ»°ã½Ì¿ÆÊéµÄÒªÉîÈëµÃ¶à£¬¶ÁÕßÐèϸР......
1. cÓïÑÔÖеÄÕûÊýÀàÐÍÓÐchar, short, int, longµÈ¼¸ÖÖ, ÏÂÃæÊÇCÓïÑÔ¶ÔÿÖÖÊý¾ÝÀàÐͳ¤¶ÈµÄ¹æ¶¨:
(a). shortºÍlongÀàÐ͵ij¤¶È²»Ïàͬ
(b). intÀàÐÍͨ³£Í¬¾ßÌå»úÆ÷µÄÎïÀí×Ö³¤Ïàͬ
(c). shortͨ³£ÊÇ16bits, intͨ³£ÊÇ16bits or 32bitsÿÖÖ±àÒëÆ÷¿ÉÒÔ¸ù¾ÝÓ²¼þµÄ²»Í¬×ÔÓÉÈ·¶¨, µ«ÊÇshortºÍint±ØÐë×îÉÙÊÇ16bits, ¶ølongÀàÐͱØÐë× ......