3 # This file illustrates the manipulation of C++ references in Tcl
5 catch { load ./example[info sharedlibextension] example}
7 # ----- Object creation -----
9 puts "Creating some objects:"
10 set a [new_Vector 3 4 5]
11 set b [new_Vector 10 11 12]
13 puts " Created [Vector_print $a]"
14 puts " Created [Vector_print $b]"
16 # ----- Call an overloaded operator -----
18 # This calls the wrapper we placed around
20 # operator+(const Vector &a, const Vector &)
22 # It returns a new allocated object.
26 puts " a+b = [Vector_print $c]"
28 # Note: Unless we free the result, a memory leak will occur
31 # ----- Create a vector array -----
33 # Note: Using the high-level interface here
34 puts "Creating an array of vectors"
36 puts " va = [va cget -this]"
39 # ----- Set some values in the array -----
41 # These operators copy the value of $a and $b to the vector array
45 # This will work, but it will cause a memory leak!
49 # The non-leaky way to do it
55 # Get some values from the array
57 puts "Getting some array values"
58 for {set i 0} {$i < 5} {incr i 1} {
59 puts " va($i) = [Vector_print [va get $i]]"
62 # Watch under resource meter to check on this
63 puts "Making sure we don't leak memory."
64 for {set i 0} {$i < 1000000} {incr i 1} {
65 set c [va get [expr {$i % 10}]]
68 # ----- Clean up -----