On 2010-11-08 11:11, Romulo Goncalves wrote: > Changeset: 5139a8cd3275 for MonetDB > URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5139a8cd3275 > Modified Files: > MonetDB5/src/optimizer/opt_datacyclotron.mx > Branch: default > Log Message: > > Add missing export. > When you realloc used make sure you set to 0 the new space. > > > diffs (25 lines): > > diff -r e0a5b904ebc0 -r 5139a8cd3275 > MonetDB5/src/optimizer/opt_datacyclotron.mx > --- a/MonetDB5/src/optimizer/opt_datacyclotron.mx Fri Nov 05 12:43:34 > 2010 +0100 > +++ b/MonetDB5/src/optimizer/opt_datacyclotron.mx Mon Nov 08 10:29:26 > 2010 +0100 > @@ -246,7 +246,7 @@ > InstrPtr *old=NULL, new, matq; > int limit; > int (*newArg)[1000]=NULL; > - char *used = NULL; > + char *used = NULL, *old_used = NULL; > (void) stk; > (void) cntxt; > > @@ -278,7 +278,11 @@ > > if ( num_regs <= (mb->vtop + 1000) ) { > regs = GDKrealloc(regs, (num_regs + DCYREGS) * > sizeof(*regs)); > - used = GDKrealloc(used, (num_regs + DCYREGS) * > sizeof(char)); > + old_used = used; > + used = GDKzalloc((num_regs + DCYREGS) * > sizeof(char)); > + memcpy(used,old_used,num_regs*sizeof(char)); > + GDKfree(old_used); > + old_used = NULL; > #ifdef BIND_DATACYCLOTRON_OPT > tpes = GDKrealloc(tpes, (num_regs + DCYREGS) * > sizeof(int)); > #endif > _______________________________________________ > Checkin-list mailing list > [email protected] > http://mail.monetdb.org/mailman/listinfo/checkin-list
This is not really a good idea. By not using realloc, you make sure that the data has to *always* be copied. Realloc is smart enough to use any unallocated space behind the buffer being reallocated if that space is large enough. In addition, you now go over part of the memory twice: once to clear it (in GDKzalloc) and once to copy over it (in the memcpy). Better is to use memset to clear the memory behind the already used area. -- Sjoerd Mullender
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
