puts "========"
puts "CR24264"
puts "========"
puts ""
#######################################################################
# OCCT 6.6.0: cutting 1600 cylinders from a box leads to out-of-memory on 32-bit system
#######################################################################

# test cutting box by many holes, inspired by
# http://www.opencascade.org/org/forum/thread_12369/?forum=3
# in OCCT 6.6.0 32-bit mode on Windows this fails with N >= 40 (out of memory)

# box plate to cut the holes from
box b 100 100 1

# N defines number of holes along each of X and Y, thus total N^2 holes
# will be drilled; note that the algorithm itself is likely to be quadratic
# for number of shapes, i.e. CPU ~ N^4 
set N 40
set holes {}
for {set i 1} {$i < $N} {incr i} {
    for {set j 1} {$j < $N} {incr j} {
       pcylinder p_${i}_$j 0.5 1
       ttranslate p_${i}_$j [expr $i * 100. / $N]  [expr $j * 100. / $N]  0.
       lappend holes p_${i}_$j
    }
}

eval compound $holes drill

set mem1 [meminfo h]

dchrono cpu restart

bcut r b drill

dchrono cpu stop counter BCut

set mem2 [meminfo h]

set mem1 [expr ${mem1}/(1024 * 1024)]
set mem2 [expr ${mem2}/(1024 * 1024)]
set mem_delta 70
puts "mem1=${mem1}"
puts "mem2=${mem2}"
puts "mem_delta=${mem_delta}"

if { [expr ${mem2} - ${mem1}] > ${mem_delta}} {
    puts "Faulty : there is memory leak"
}

vinit
vdisplay r
vfit
