1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: reduce the memory usage of the clock example, without -autofree & -gc boehm

This commit is contained in:
Delyan Angelov 2021-11-11 17:38:45 +02:00
parent c8cb1bf6b4
commit 9cb378bb6b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 5 additions and 2 deletions

View File

@ -88,11 +88,12 @@ fn on_frame(mut app App) {
}
// Rotate a polygon round the centerpoint
[manualfree]
fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx.Color, angle f32) {
sa := math.sin(math.pi * angle / 180.0)
ca := math.cos(math.pi * angle / 180.0)
mut rotated_points := []f32{}
mut rotated_points := []f32{cap: points.len}
for i := 0; i < points.len / 2; i++ {
x := points[2 * i]
y := points[2 * i + 1]
@ -102,6 +103,7 @@ fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx
rotated_points << (yn + center) * dpi_scale
}
ctx.draw_convex_poly(rotated_points, c)
unsafe { rotated_points.free() }
}
fn (mut app App) resize() {
@ -133,7 +135,7 @@ fn on_event(e &gg.Event, mut app App) {
.q {
println('Good bye.')
// do we need to free anything here?
exit(0)
app.gg.quit()
}
else {}
}

View File

@ -237,6 +237,7 @@ fn gg_cleanup_fn(user_data voidptr) {
if g.config.cleanup_fn != voidptr(0) {
g.config.cleanup_fn(g.config.user_data)
}
gfx.shutdown()
}
fn gg_fail_fn(msg &char, user_data voidptr) {