Java Memory Free getTilesBasedOnFreeMemory(int rows, int cols)

Here you can find the source of getTilesBasedOnFreeMemory(int rows, int cols)

Description

Calculates optimal tile size for the actual free memory.

License

Open Source License

Parameter

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.

Declaration

public static int[] getTilesBasedOnFreeMemory(int rows, int cols) 

Method Source Code

//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 };
    }
}

Related

  1. getJavaFreeMemory()
  2. getJvmFreeMemory()
  3. getMemoryFree()
  4. getMemoryFree()
  5. getSystemFreeMemory()
  6. hasFreeMemory(float margin)
  7. isFreeMemoryAvailable()
  8. jvmFreeMemory(String size, Boolean txtByte)
  9. memoryFree()