File: OutOfMemory.java

package info (click to toggle)
glpk-java 1.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,580 kB
  • sloc: sh: 3,609; java: 1,794; xml: 259; makefile: 154; ansic: 35
file content (34 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (4)
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
import org.gnu.glpk.GLPK;
import org.gnu.glpk.GLPKConstants;
import org.gnu.glpk.SWIGTYPE_p_double;
import org.gnu.glpk.SWIGTYPE_p_int;

/**
 * This example file demonstrates that OutOfMemoryErrors are
 * thrown if calloc fails.
 */
public class OutOfMemory {

    /**
     * This is the main function.
     */
    public static void main(String[] args) {
        SWIGTYPE_p_int ind;

        System.out.println("Testing allocation of integer array.");
        System.out.println("1: No error should occur");
        ind = GLPK.new_intArray(3);
	GLPK.delete_intArray(ind);
	System.out.println("1: Success");
	try {
	    System.out.println("2: Error should occur");
	    ind = GLPK.new_intArray(-1);
	} catch (OutOfMemoryError ex) {
	    ex.printStackTrace(System.out);
	    System.out.println("2: Success");
            System.exit(0);
	}
        System.out.println("2: Failure");
        System.exit(1);
    }
}