1 #include "alloc.h" 2 #include "libcflat.h" 3 #include "vmalloc.h" 4 5 static int sieve(char* data, int size) 6 { 7 int i, j, r = 0; 8 9 for (i = 0; i < size; ++i) 10 data[i] = 1; 11 12 data[0] = data[1] = 0; 13 14 for (i = 2; i < size; ++i) 15 if (data[i]) { 16 ++r; 17 for (j = i*2; j < size; j += i) 18 data[j] = 0; 19 } 20 return r; 21 } 22 23 static void test_sieve(const char *msg, char *data, int size) 24 { 25 int r; 26 27 printf("%s:", msg); 28 r = sieve(data, size); 29 printf("%d out of %d\n", r, size); 30 } 31 32 #define STATIC_SIZE 1000000 33 #define VSIZE 100000000 34 char static_data[STATIC_SIZE]; 35 36 int main(void) 37 { 38 void *v; 39 int i; 40 41 printf("starting sieve\n"); 42 test_sieve("static", static_data, STATIC_SIZE); 43 setup_vm(); 44 test_sieve("mapped", static_data, STATIC_SIZE); 45 for (i = 0; i < 3; ++i) { 46 v = malloc(VSIZE); 47 test_sieve("virtual", v, VSIZE); 48 free(v); 49 } 50 51 return 0; 52 } 53