From 309accb98349e00fe832b1c7681656bae2e3673e Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 11 Sep 2006 07:01:39 +0000 Subject: [PATCH] memory control for ymage generation: the ymageMatrix initializer throws an RuntimeException if there is not enough memory available to generate a new ymage of wanted size git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2541 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/server/serverMemory.java | 7 +++++++ source/de/anomic/ymage/ymageMatrix.java | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/server/serverMemory.java b/source/de/anomic/server/serverMemory.java index 939ed7ff4..4238159a3 100644 --- a/source/de/anomic/server/serverMemory.java +++ b/source/de/anomic/server/serverMemory.java @@ -57,6 +57,13 @@ public class serverMemory { // memory that is free without increasing of total memory taken from os return runtime.freeMemory(); } + + public static boolean available(long memory, boolean gciffail) { + if (available() >= memory) return true; + if (!gciffail) return false; + System.gc(); + return (available() >= memory); + } public static long available() { // memory that is available including increasing total memory up to maximum diff --git a/source/de/anomic/ymage/ymageMatrix.java b/source/de/anomic/ymage/ymageMatrix.java index 6896a1251..70a77a457 100644 --- a/source/de/anomic/ymage/ymageMatrix.java +++ b/source/de/anomic/ymage/ymageMatrix.java @@ -47,6 +47,8 @@ package de.anomic.ymage; +import de.anomic.server.serverMemory; + public class ymageMatrix implements Cloneable { // colors regarding RGB Color Model @@ -72,7 +74,8 @@ public class ymageMatrix implements Cloneable { private byte defaultMode; private boolean grabComplementary = false; - public ymageMatrix(ymageMatrix matrix) { + public ymageMatrix(ymageMatrix matrix) throws RuntimeException { + if (serverMemory.available(1024 * 1024 + 3 * width * height, true)) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available"); // clones the matrix this.width = matrix.width; this.height = matrix.height; @@ -90,6 +93,7 @@ public class ymageMatrix implements Cloneable { } public ymageMatrix(int width, int height, long backgroundColor) { + if (serverMemory.available(1024 * 1024 + 3 * width * height, true)) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available"); this.width = width; this.height = height; this.defaultColR = 0xFF;