File: malloc.c

package info (click to toggle)
clisp 1%3A2.44.1-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 40,080 kB
  • ctags: 12,945
  • sloc: lisp: 77,546; ansic: 32,166; xml: 25,161; sh: 11,568; fortran: 7,094; cpp: 2,636; makefile: 1,234; perl: 164
file content (31 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (9)
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
/* compile:  cc -o malloc malloc.c
   try:      malloc 50000
             malloc 100000
             malloc 1000000
*/
#include <stdio.h>

void printf_address (unsigned long addr) {
  if (sizeof(unsigned long) <= 4)
    printf ("#x%08X", (unsigned int)addr);
  else
    printf ("#x%08X%08X",(unsigned int)(addr>>32),
            (unsigned int)(addr & 0xFFFFFFFF));
}

void test_malloc (unsigned long size) {
  unsigned long result = (unsigned long)malloc(size);
  printf ("malloc(%12d) = ",size); printf_address (result); printf ("\n");
}

int main (int argc, char* argv[]) {
  int i;
  if (argc == 1)
    for (i = 1; i < 40; i++)
      test_malloc(1 << i);
  else
    for (i = 1; i < argc; i++)
      test_malloc(atol(argv[i]));
  printf ("&main = "); printf_address ((unsigned long)&main); printf ("\n");
  return 0;
}