[GRASS-SVN] r70961 - grass-addons/grass7/imagery/i.superpixels.slic
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 26 14:53:38 PDT 2017
Author: mmetz
Date: 2017-04-26 14:53:38 -0700 (Wed, 26 Apr 2017)
New Revision: 70961
Modified:
grass-addons/grass7/imagery/i.superpixels.slic/cache.c
Log:
i.superpixels.slic: optimize memory allocation for memory cache
Modified: grass-addons/grass7/imagery/i.superpixels.slic/cache.c
===================================================================
--- grass-addons/grass7/imagery/i.superpixels.slic/cache.c 2017-04-26 21:51:02 UTC (rev 70960)
+++ grass-addons/grass7/imagery/i.superpixels.slic/cache.c 2017-04-26 21:53:38 UTC (rev 70961)
@@ -49,9 +49,15 @@
int row, col;
c->r = G_malloc(sizeof(char **) * c->rows);
- for (row = 0; row < c->rows; row++) {
- c->r[row] = G_malloc(sizeof(char *) * c->cols);
- c->r[row][0] = G_malloc(sizeof(char) * c->cols * c->n);
+ row = 0;
+ c->r[row] = G_malloc(sizeof(char *) * c->rows * c->cols);
+ c->r[row][0] = G_malloc(sizeof(char) * c->rows * c->cols * c->n);
+ for (col = 1; col < c->cols; col++) {
+ c->r[row][col] = c->r[row][col - 1] + c->n;
+ }
+ for (row = 1; row < c->rows; row++) {
+ c->r[row] = c->r[row - 1] + c->cols;
+ c->r[row][0] = c->r[row - 1][0] + c->cols * c->n;
for (col = 1; col < c->cols; col++) {
c->r[row][col] = c->r[row][col - 1] + c->n;
}
More information about the grass-commit
mailing list