File: runme.go

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (71 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This example illustrates the manipulation of C++ references in Java.

package main

import (
	. "./example"
	"fmt"
)

func main() {
	fmt.Println("Creating some objects:")
	a := NewVector(3, 4, 5)
	b := NewVector(10, 11, 12)

	fmt.Println("    Created ", a.Print())
	fmt.Println("    Created ", b.Print())

	// ----- Call an overloaded operator -----

	// This calls the wrapper we placed around
	//
	//      operator+(const Vector &a, const Vector &)
	//
	// It returns a new allocated object.

	fmt.Println("Adding a+b")
	c := Addv(a, b)
	fmt.Println("    a+b = " + c.Print())

	// Because addv returns a reference, Addv will return a
	// pointer allocated using Go's memory allocator.  That means
	// that it will be freed by Go's garbage collector, and we can
	// not use DeleteVector to release it.

	c = nil

	// ----- Create a vector array -----

	fmt.Println("Creating an array of vectors")
	va := NewVectorArray(10)
	fmt.Println("    va = ", va)

	// ----- Set some values in the array -----

	// These operators copy the value of Vector a and Vector b to
	// the vector array
	va.Set(0, a)
	va.Set(1, b)

	va.Set(2, Addv(a, b))

	// Get some values from the array

	fmt.Println("Getting some array values")
	for i := 0; i < 5; i++ {
		fmt.Println("    va(", i, ") = ", va.Get(i).Print())
	}

	// Watch under resource meter to check on this
	fmt.Println("Making sure we don't leak memory.")
	for i := 0; i < 1000000; i++ {
		c = va.Get(i % 10)
	}

	// ----- Clean up ----- This could be omitted. The garbage
	// collector would then clean up for us.
	fmt.Println("Cleaning up")
	DeleteVectorArray(va)
	DeleteVector(a)
	DeleteVector(b)
}