blob: f8d46d8a578b8c2adb5188ae83bc226fcb26bb0e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// growable arrays and fixed ones
struct point { int x, y; };
fn main()
{
let before = live_objects();
{
[]int a = new([]int);
for (int i = 0; i < 100; i++) push(a, i * i);
putn(len(a)); putc(' '); putn(cap(a)); putc(' '); putn(a[99]); putc(' ');
putn(pop(a)); putc(' '); putn(len(a)); putc(' ');
resize(a, 3); putn(len(a)); putc(' '); putn(a[2]); putc(' ');
fixed []int f = new(fixed []int, 5);
f[4] = 7; putn(f[4] + len(f)); putc(' ');
[]point ps = new([]point, 2);
ps[1].y = 9; resize(ps, 10); putn(ps[1].y + len(ps)); putc(' ');
[8]int st; putn(len(st)); putc(' ');
[]*point owned = new([]*point);
for (int i = 0; i < 20; i++) { *point p = new(point); p.x = i; push(owned, d*p); }
putn(owned[19].x); putc(' ');
putn(live_objects() - before); putc(10);
}
putn(live_objects() - before); putc(10);
return 0;
}
|