7 #include "../memcheck.h"
23 allocate_from_pool(struct pool
*p
, size_t n
)
25 void *a
= p
->buf
+ p
->used
;
26 assert(p
->used
+ n
< p
->allocated
);
27 VALGRIND_MEMPOOL_ALLOC(p
, a
, n
);
35 struct pool
*p
= malloc(sizeof(struct pool
));
39 p
->buf
= malloc(p
->allocated
);
41 memset(p
->buf
, 0, p
->allocated
);
42 VALGRIND_CREATE_MEMPOOL(p
, 0, 0);
43 (void) VALGRIND_MAKE_MEM_NOACCESS(p
->buf
, p
->allocated
);
53 void set_flags ( int n
)
92 struct cell
*cells_static
[N
];
95 int main( int argc
, char** argv
)
97 struct cell
*cells_local
[N
];
100 struct pool
*p
= allocate_pool();
101 struct cell
**cells
= static_roots
? cells_static
: cells_local
;
105 assert(strlen(argv
[1]) == 1);
106 assert(argv
[1][0] >= '0' && argv
[1][0] <= '5');
107 arg
= atoi( argv
[1] );
110 memset(cells_static
, 0, sizeof(cells_static
));
111 memset(cells_local
, 0, sizeof(cells_local
));
113 for (i
= 0; i
< N
; ++i
) {
114 cells
[i
] = allocate_from_pool(p
, sizeof(struct cell
));
118 VALGRIND_MEMPOOL_TRIM(p
,
119 p
->buf
+(10 * sizeof(struct cell
)),
120 20 * sizeof(struct cell
) + 2);
123 VALGRIND_DESTROY_MEMPOOL(p
);