[GRASS-SVN] r59014 - grass/trunk/raster/r.li/r.li.daemon
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 13 01:13:28 PST 2014
Author: mmetz
Date: 2014-02-13 01:13:28 -0800 (Thu, 13 Feb 2014)
New Revision: 59014
Modified:
grass/trunk/raster/r.li/r.li.daemon/daemon.h
grass/trunk/raster/r.li/r.li.daemon/worker.c
Log:
r.li.daemon: fix cache management
Modified: grass/trunk/raster/r.li/r.li.daemon/daemon.h
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/daemon.h 2014-02-12 21:25:39 UTC (rev 59013)
+++ grass/trunk/raster/r.li/r.li.daemon/daemon.h 2014-02-13 09:13:28 UTC (rev 59014)
@@ -100,6 +100,7 @@
* \member y the y coordinate of upper left corner
* \member rl area length in rows
* \member cl area length in columns
+ * \member rc number of rows in the cache
* \member mask file descriptor of mask raster file (-1 if there is no mask)
*/
struct area_entry
@@ -108,6 +109,7 @@
int y;
int rl;
int cl;
+ int rc;
int mask;
int data_type;
cell_manager cm;
Modified: grass/trunk/raster/r.li/r.li.daemon/worker.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/worker.c 2014-02-12 21:25:39 UTC (rev 59013)
+++ grass/trunk/raster/r.li/r.li.daemon/worker.c 2014-02-13 09:13:28 UTC (rev 59014)
@@ -73,6 +73,8 @@
switch (data_type) {
case CELL_TYPE:{
cache_rows = CACHESIZE / (hd.cols * sizeof(CELL));
+ if (cache_rows < 4)
+ cache_rows = 4;
cm->cache = G_malloc(cache_rows * sizeof(CELL *));
cm->contents = G_malloc(cache_rows * sizeof(int));
cm->used = 0;
@@ -80,6 +82,8 @@
} break;
case DCELL_TYPE:{
cache_rows = CACHESIZE / (hd.cols * sizeof(DCELL));
+ if (cache_rows < 4)
+ cache_rows = 4;
dm->cache = G_malloc(cache_rows * sizeof(DCELL *));
dm->contents = G_malloc(cache_rows * sizeof(int));
dm->used = 0;
@@ -87,6 +91,8 @@
} break;
case FCELL_TYPE:{
cache_rows = CACHESIZE / (hd.cols * sizeof(FCELL));
+ if (cache_rows < 4)
+ cache_rows = 4;
fm->cache = G_malloc(cache_rows * sizeof(FCELL *));
fm->contents = G_malloc(cache_rows * sizeof(int));
fm->used = 0;
@@ -94,6 +100,7 @@
} break;
}
ad->data_type = data_type;
+ ad->rc = cache_rows;
ad->cm = cm;
ad->fm = fm;
ad->dm = dm;
@@ -144,34 +151,34 @@
}
/* memory menagement */
- if (ad->rl > used) {
+ if (ad->rc > used) {
/* allocate cache */
int i;
switch (data_type) {
case CELL_TYPE:{
- for (i = 0; i < (ad->rl - used); i++) {
+ for (i = 0; i < (ad->rc - used); i++) {
cm->cache[used + i] = Rast_allocate_c_buf();
}
}
break;
case DCELL_TYPE:{
- for (i = 0; i < ad->rl - used; i++) {
+ for (i = 0; i < ad->rc - used; i++) {
dm->cache[used + i] = Rast_allocate_d_buf();
}
}
break;
case FCELL_TYPE:{
- for (i = 0; i < ad->rl - used; i++) {
+ for (i = 0; i < ad->rc - used; i++) {
fm->cache[used + i] = Rast_allocate_f_buf();
}
}
break;
}
- cm->used = ad->rl;
- dm->used = ad->rl;
- fm->used = ad->rl;
- used = ad->rl;
+ cm->used = ad->rc;
+ dm->used = ad->rc;
+ fm->used = ad->rc;
+ used = ad->rc;
}
/* calculate function */
@@ -245,6 +252,10 @@
}
close(mask_fd);
+
+ G_free(buf);
+ G_free(old);
+
return G_store(tmp_file);
}
@@ -252,7 +263,7 @@
{
int hash;
- hash = row % ad->rl;
+ hash = row % ad->rc;
if (ad->cm->contents[hash] == row)
return ad->cm->cache[hash];
else {
@@ -267,7 +278,7 @@
{
int hash;
- hash = row % ad->rl;
+ hash = row % ad->rc;
if (ad->dm->contents[hash] == row)
return ad->dm->cache[hash];
else {
@@ -282,7 +293,7 @@
{
int hash;
- hash = row % ad->rl;
+ hash = row % ad->rc;
if (ad->fm->contents[hash] == row)
return ad->fm->cache[hash];
else {
More information about the grass-commit
mailing list