首页 > 代码库 > 8亿个整数存储

8亿个整数存储

用int型存储占 800000000 * 4 / 1000 /1000/ = 3200M = 3.2G

用位数组存储占 3.2G /32 = 100M

#include<stdio.h>#include "tire.h"#include "limits.h"#define BITSLOTS(nb) (nb + CHAR_BIT -1)/CHAR_BIT#define BITMASK(b) (1 << ((b) % CHAR_BIT))#define BITSLOT(b) ((b)/CHAR_BIT)#define BITSET(a,b) ((a)[BITSLOT(b)] |= BITMASK(b))#define BITCLEAR(a,b) ((a)[BITSLOT(b)] &= ~BITMASK(b))#define BITTEST(a,b) ((a)[BITSLOT(b)] & BITMASK(b))int main(int,char**){	char* bitarray = new char[BITSLOTS(1000 * 1000 * 800)];	for(int i = 0;i< BITSLOTS(1000 * 1000 * 800);i++)		bitarray[i] = 0;	for(int i = 0;i< 1000 * 1000 * 800;i++)	{		if((i % (1000 * 1000 * 10)) != 0)		{			BITSET(bitarray,i);		}	}		for(int i = 0;i< 1000 * 1000 * 800;i++)	{		if(!BITTEST(bitarray,i))		{			printf("i==%d \n",i);		}	}		getchar();	return 0;}

 

8亿个整数存储