File: arb_flush_mem.cxx

package info (click to toggle)
arb 6.0.2-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie-kfreebsd
  • size: 65,852 kB
  • sloc: ansic: 394,903; cpp: 250,252; makefile: 19,635; sh: 15,878; perl: 10,461; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (44 lines) | stat: -rw-r--r-- 1,615 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ================================================================ //
//                                                                  //
//   File      : arb_flush_mem.cxx                                  //
//   Purpose   :                                                    //
//                                                                  //
//   Coded by Ralf Westram (coder@reallysoft.de) in December 2012   //
//   Institute of Microbiology (Technical University Munich)        //
//   http://www.arb-home.de/                                        //
//                                                                  //
// ================================================================ //

#include <arbdb.h>
#include <arb_misc.h>
#include <arb_progress.h>

int ARB_main(int , char *[]) {
    GB_ULONG blocks_to_flush  = GB_get_usable_memory()*4; // no of 256b-blocks
    GB_ULONG mem_to_flush = blocks_to_flush*256;
    printf("Flushing %s of your memory\n", GBS_readable_size(mem_to_flush, "b"));

    unsigned char *mem = (unsigned char *)malloc(mem_to_flush);
    {
        arb_progress progress("writing mem", blocks_to_flush);
        for (GB_ULONG p = 0; p<mem_to_flush; ++p) {
            mem[p] = (unsigned char)p;
            if (!mem[p]) ++progress;
        }
    }
#if 0
    ulong sum = 0;
    {
        arb_progress progress("reading mem", blocks_to_flush);
        for (GB_ULONG p = 0; p<mem_to_flush; ++p) {
            sum += mem[p];
            if (!mem[p]) ++progress;
        }
    }
    printf("done with sum=%lu\n", sum);
#endif

    free(mem);

    return EXIT_SUCCESS;
}