Here you can find the source of getTilesBasedOnFreeMemory(int rows, int cols)
Parameter | Description |
---|---|
rows | the rows of the complete image the tiles are calculated for. |
cols | the cols of the complete image the tiles are calculated for. |
public static int[] getTilesBasedOnFreeMemory(int rows, int cols)
//package com.java2s; /*//ww w. jav a2s.c o m * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2006-2010, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ public class Main { /** * Calculates optimal tile size for the actual free memory. * * @param rows the rows of the complete image the tiles are calculated for. * @param cols the cols of the complete image the tiles are calculated for. * @return */ public static int[] getTilesBasedOnFreeMemory(int rows, int cols) { long freeMemory = Runtime.getRuntime().freeMemory(); int tileSizeY = 256; int tileSizeX = 256; if (freeMemory > 8L * cols) { tileSizeX = cols; tileSizeY = (int) (freeMemory / 8) / cols; if (tileSizeY > rows) { tileSizeY = rows; } } return new int[] { tileSizeX, tileSizeY }; } }