Changeset: 425bb35f7aea for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=425bb35f7aea
Modified Files:
monetdb5/modules/mal/cluster.mx
monetdb5/optimizer/opt_cluster.mx
Branch: Aug2011
Log Message:
Remove alloca calls
diffs (145 lines):
diff --git a/monetdb5/modules/mal/cluster.mx b/monetdb5/modules/mal/cluster.mx
--- a/monetdb5/modules/mal/cluster.mx
+++ b/monetdb5/modules/mal/cluster.mx
@@ -413,7 +413,7 @@
mnstr_printf(GDKout,"bucket pages %d size %d max %d N %d\n",
(int)MT_npages(), (int)bsize, (int)rng, (int)N);
#endif
- basket = (Basket*) alloca((N+1) * sizeof(Basket));
+ basket = (Basket*) GDKzalloc((N+1) * sizeof(Basket));
if (basket==NULL)
throw(MAL, "cluster.new", MAL_MALLOC_FAIL);
@@ -462,6 +462,7 @@
BATaccessEnd(map,USE_TAIL,MMAP_WILLNEED);
BBPunfix(*B);
BBPkeepref(*RB= map->batCacheid);
+ GDKfree(basket);
return MAL_SUCCEED;
}
/*
@@ -612,7 +613,7 @@
}
/* convert histogram into prefix sum */
- pos = (wrd*)alloca(sizeof(wrd) * (mask+1));
+ pos = (wrd*)GDKzalloc(sizeof(wrd) * (mask+1));
for (sum = 0, i=0 ; i <= mask; i++) {
wrd psum = sum;
@@ -624,6 +625,7 @@
if ((cmap = BATnew(TYPE_void, TYPE_wrd, BATcount(b))) == NULL) {
BBPunfix(*B);
BBPunfix(psum->batCacheid);
+ GDKfree(pos);
throw(MAL, "cluster.new", MAL_MALLOC_FAIL);
}
BATseqbase(cmap, b->H->seq);
@@ -639,6 +641,7 @@
*m++ = pos[h]++;
}
+ GDKfree(pos);
BBPunfix(*B);
BBPkeepref(*rpsum = psum->batCacheid);
BBPkeepref(*rcmap = cmap->batCacheid);
diff --git a/monetdb5/optimizer/opt_cluster.mx
b/monetdb5/optimizer/opt_cluster.mx
--- a/monetdb5/optimizer/opt_cluster.mx
+++ b/monetdb5/optimizer/opt_cluster.mx
@@ -81,7 +81,7 @@
{
int i, j = 0;
InstrPtr q;
- int *grp = (int*) alloca(sizeof(int) * MAX_STMTS);
+ int *grp = (int*) GDKzalloc(sizeof(int) * MAX_STMTS);
int state = GRP_NEW;
int h = 0, g = 0, cnts = 0, cntl = 0, cntr = 0;
@@ -156,6 +156,7 @@
/* lets cluster */
}
#endif
+ GDKfree(grp);
return 1;
}
#endif
@@ -231,7 +232,7 @@
s = pushArgument( mb, s, getArg(c, 0) ); /* psum */
/* order these parts then pack2 */
- no = (InstrPtr*)alloca(sizeof(InstrPtr)*nr_parts);
+ no = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
o = old[ord[0]];
for (p = 0; p<nr_parts; p++) {
no[p] = copyInstruction(o);
@@ -319,6 +320,7 @@
if (old[i])
freeInstruction(old[i]);
GDKfree(old);
+ GDKfree(no);
}
return 1;
}
@@ -327,8 +329,8 @@
cluster_orderby(MalBlkPtr mb)
{
int i, j = 0, k = 0, o = 0, state = ORDERBY_NONE, actions = 0;
- int *ord = (int*) alloca(sizeof(int) * MAX_STMTS);
- int *prj = (int*) alloca(sizeof(int) * MAX_STMTS);
+ int *ord = (int*) GDKzalloc(sizeof(int) * MAX_STMTS);
+ int *prj = (int*) GDKzalloc(sizeof(int) * MAX_STMTS);
InstrPtr q;
/* TODO only cluster on large inputs */
@@ -381,6 +383,8 @@
}
if (k && j && state == ORDERBY_JOIN)
actions = _cluster_orderby(mb, ord, j, prj, k);
+ GDKfree(ord);
+ GDKfree(prj);
return actions;
}
@@ -475,9 +479,9 @@
/* join these parts */
njn0 = getArg(q, 0);
- njn = (InstrPtr*)alloca(sizeof(InstrPtr)*nr_parts);
- mr = (InstrPtr*)alloca(sizeof(InstrPtr)*nr_parts);
- rmr = (InstrPtr*)alloca(sizeof(InstrPtr)*nr_parts);
+ njn = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
+ mr = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
+ rmr = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
jn = old[join[0]];
for (p = 0; p<nr_parts; p++) {
InstrPtr r = newStmt2( mb, batRef, reverseRef);
@@ -575,6 +579,9 @@
if (old[i])
freeInstruction(old[i]);
GDKfree(old);
+ GDKfree(njn);
+ GDKfree(mr);
+ GDKfree(rmr);
}
return 1;
}
@@ -583,8 +590,8 @@
cluster_join(MalBlkPtr mb)
{
int i, j = 0, k = 0, jn = 0, mr = -1, rmr = -1, state = JOIN_NONE,
state_mr = JOIN_NONE, state_rmr = JOIN_NONE, actions = 0;
- int *join = (int*) alloca(sizeof(int) * MAX_STMTS);
- int *prj = (int*) alloca(sizeof(int) * MAX_STMTS);
+ int *join = (int*) GDKzallov(sizeof(int) * MAX_STMTS);
+ int *prj = (int*) GDKzallov(sizeof(int) * MAX_STMTS);
InstrPtr q;
/* locate the a sequence of group.new/derive statements */
@@ -657,6 +664,8 @@
}
if (k && j && (state_mr == JOIN_PRJ || state_rmr == JOIN_PRJ))
actions = _cluster_join(mb, join, j, prj, k);
+ GDKfree(join);
+ GDKfree(prj);
return actions;
}
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list