ARB
arb_flush_mem.cxx
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : arb_flush_mem.cxx //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in December 2012 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ================================================================ //
11 
12 #include <arbdb.h>
13 #include <arb_misc.h>
14 #include <arb_progress.h>
15 
16 int ARB_main(int , char *[]) {
17  GB_ULONG blocks_to_flush = GB_get_usable_memory()*4; // no of 256b-blocks
18  GB_ULONG mem_to_flush = blocks_to_flush*256;
19  printf("Flushing %s of your memory\n", GBS_readable_size(mem_to_flush, "b"));
20 
21  unsigned char *mem = (unsigned char *)malloc(mem_to_flush);
22  {
23  arb_progress progress("writing mem", blocks_to_flush);
24  for (GB_ULONG p = 0; p<mem_to_flush; ++p) {
25  mem[p] = (unsigned char)p;
26  if (!mem[p]) ++progress;
27  }
28  }
29 #if 0
30  ulong sum = 0;
31  {
32  arb_progress progress("reading mem", blocks_to_flush);
33  for (GB_ULONG p = 0; p<mem_to_flush; ++p) {
34  sum += mem[p];
35  if (!mem[p]) ++progress;
36  }
37  }
38  printf("done with sum=%lu\n", sum);
39 #endif
40 
41  free(mem);
42 
43  return EXIT_SUCCESS;
44 }
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
unsigned long GB_ULONG
Definition: arbdb_base.h:42
int ARB_main(int, char *[])
const char * GBS_readable_size(unsigned long long size, const char *unit_suffix)
Definition: arb_misc.cxx:23
GB_ULONG GB_get_usable_memory(void)
Definition: adsocket.cxx:865