10 * This is a simple program to exercise the allocator. It allocates and frees
11 * memory in a pseudo-random fashion. It should run silently, using up time
12 * and resources on your system until you stop it or until it has gone
13 * through TEST_DURATION (or the argument) iterations of the loop.
16 extern C_LINKAGE
double drand48(void); /* For pre-ANSI C systems */
18 #define POOL_SIZE 1024
19 #define LARGEST_BUFFER 30000
20 #define TEST_DURATION 1000000
22 void * pool
[POOL_SIZE
];
26 * Add -DFAKE_DRAND48 to your compile flags if your system doesn't
31 #define ULONG_MAX ~(1L)
37 return (random() / (double)ULONG_MAX
);
42 main(int argc
, char * * argv
)
45 int duration
= TEST_DURATION
;
48 duration
= atoi(argv
[1]);
50 for ( ; count
< duration
; count
++ ) {
51 void * * element
= &pool
[(int)(drand48() * POOL_SIZE
)];
52 size_t size
= (size_t)(drand48() * (LARGEST_BUFFER
+ 1));
58 else if ( size
> 0 ) {
59 *element
= malloc(size
);