aboutsummaryrefslogtreecommitdiff
path: root/docs/history/15-o3/code/tests/buddy.zc
blob: 2000598aaccf082c706fa5f6f7412f9d18b30943 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// the buddy allocator: 20000 small blocks, freed, merge back into one big one
let keep[20000];
fn main()
{
	let i = 0, p;
	while (i < 20000) { keep[i] = new(2); i++; }   // 20000 8-word blocks
	putn(largest_free()); putc(' ');
	i = 0; while (i < 20000) { free(keep[i]); i++; }
	putn(largest_free()); putc(' ');
	p = new(200000);	// only possible if the small blocks merged back
	putn(osize(p) >= 200000); putc(' ');
	free(d*p);
	putn(live_objects()); putc(10);
	return 0;
}