Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Memory leak...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 13 Topic 2195 of 2317
Post > Topic >>

Re: Memory leak of iterations in large hash.

by iaminsik <iaminsik@[EMAIL PROTECTED] > Mar 17, 2008 at 09:30 PM

On 3=BF=F918=C0=CF, =BF=C0=C8=C412=BD=C341=BA=D0, Joel Reicher
<j...@[EMAIL PROTECTED]
> wrote:
> iaminsik <iamin...@[EMAIL PROTECTED]
> writes:
> > Hi, I compared one element with others in a Hash (size : about 7,000).
>
> >
------------------------------------------------------------------------=

> > for(word1 in arrword)
> > {
> >    for(word2 in arrword)
> >    {
> >        # compare word1 with word2.
> >    }
> > }
> >
------------------------------------------------------------------------=

>
> > But, in every iteration, the memory-usage increased.
>
> > Somebody help me?
>
> I would guess your comparison procedure is causing memory allocation,
> but you haven't said what it's doing.

I experimented word-similarity with predicates.
My source code is very long.... In the sub-routines, I frequently
split a tring into an array, and delete the array.

If you have some times, let me know memory bugs...

  print "calc similarity";
  for(word1 in arrword)
  {
    I1 =3D I_of_word(arrword[word1], cnt_all_noun_type);
    for(word2 in arrword)
    {
      if(word1 !=3D word2 && arrwordfreq[word1]>10 &&
arrwordfreq[word2]>10 )
      #if(word1 !=3D word2 )
      {
        I2 =3D I_of_word(arrword[word2], cnt_all_noun_type);
        ret =3D Co_I_of_words(arrword[word1], cnt_all_noun_type, word2);
        ln=3Dsplit(ret, arrret, SUBSEP);
        ISame =3D arrret[1];
        ISame =3D ISame * 2;
        I =3D ISame / ( I1 + I2);
        if( I )
          print word1 "(" arrwordfreq[word1] ")", I, word2 "("
arrwordfreq[word2] ")", arrret[2], arrret[3] > "Dekang_over10.txt";
        delete arrret;
      }
    }
  }
}

# Co-Information Sum between Two Words
function Co_I_of_words (features,cnt_all_type,word2) # divided by [|]
{
  cofeatures1=3Dcofeatures2=3D"";
  I=3D0.0;
  word1num=3Dsplit(features,arrfeature2,"[|]");
  for(i=3D1;i<=3Dword1num;i++)
  {
    # check whether word2 has the same feature.
    if(arrwordfeaturerelation[word2 SUBSEP arrfeature2[i]] !=3D 0)
    {
      I +=3D I_of_feature(arrfeature2[i], cnt_all_type);
      arrfeaturestr=3Darrfeature2[i];
      gsub(SUBSEP, "/", arrfeaturestr);
      cofeatures2=3Dcofeatures2 (cofeatures2=3D=3D""?"":"|") arrfeaturestr
\=

            "(" arrwordfeaturerelation[word2 SUBSEP arrfeature2[i]]
")";
      cofeatures1=3Dcofeatures1 (cofeatures1=3D=3D""?"":"|") arrfeaturestr
\=

            "(" arrwordfeaturerelation[word1 SUBSEP arrfeature2[i]]
")";
    }
    else
      delete arrwordfeaturerelation[word2 SUBSEP arrfeature2[i]];
  }
  delete arrfeature2;

  retval=3DI SUBSEP cofeatures1 SUBSEP cofeatures2;
  return retval;
}

# Information Sum of Word
function I_of_word (features,cnt_all_type) # divided by [|]
{
  I=3D0.0;
  word1num=3Dsplit(features,arrfeature1,"[|]");
  for(i=3D1;i<=3Dword1num;i++)
  {
    I +=3D I_of_feature(arrfeature1[i], cnt_all_type);
  }
  delete arrfeature1;

  return I;
}

# Information A Feature
function I_of_feature (feature_relation,cnt_all_type) # divided by [|]
{
  lchild=3Dsplit(arrfeature[feature_relation],div,"[|]");
  delete div;
  return -log(lchild / cnt_all_type);
}

# NonDuplicateString
function InsertArrayString (ArrString, newbie)
{
  n=3Dsplit(ArrString, Container, "[|]");
  bflag=3D0;
  for(i=3D1;i<=3Dn;i++)
  {
    if(Container[i]=3D=3Dnewbie) bflag=3D1;
  }
  delete Container;
  if(bflag=3D=3D0)
    ArrString =3D ArrString (ArrString=3D=3D""?"":"|") newbie;
  return ArrString;
}

# Get Function String
function CleanStringToFunc  (String)
{
  retstr=3D"";
  n=3Dsplit(String, Arrstr, " [+] ");
  for(i=3D1;i<=3Dn;i++)
  {
    if(Arrstr[i] ~ /\/fjc/)
    {
      tempstr=3DArrstr[i];
      gsub(/^[^\/]*\//,"",tempstr);
      delete Arrstr;
      return tempstr;
    }
  }
  delete Arrstr;
  return "NULL";
}

# CleanString
function CleanStringToVerb  (String)
{
  retstr=3D"";
  n=3Dsplit(String, Arrstr, " [+] ");
  for(i=3D1;i<=3Dn;i++)
  {
    if(Arrstr[i] ~ /\/CMC/ || Arrstr[i] ~ /\/YBDO/ \
      || Arrstr[i] ~ /\/YBHO/ \
      || Arrstr[i] ~ /\/fpd/ || Arrstr[i] ~ /\/fph/)
    {
      if(retstr=3D=3D"") retstr =3D retstr Arrstr[i];
      else retstr =3D retstr " + " Arrstr[i];
    }
  }
  delete Arrstr;
  return retstr;
}

Thanks!
Remi.

>
> Cheers,
>
>         - Joel- =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BC=FB=B1=E2=B1=E2 -
>
> - =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BA=B8=B1=E2 -
 




 13 Posts in Topic:
Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-17 20:29:41 
Re: Memory leak of iterations in large hash.
Joel Reicher <joel@[EM  2008-03-18 03:41:41 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-17 21:30:04 
Re: Memory leak of iterations in large hash.
Ed Morton <morton@[EMA  2008-03-18 06:43:13 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-18 05:53:41 
Re: Memory leak of iterations in large hash.
Ed Morton <morton@[EMA  2008-03-18 08:11:13 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-18 07:12:18 
Re: Memory leak of iterations in large hash.
Ed Morton <morton@[EMA  2008-03-18 09:37:42 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-18 07:57:27 
Re: Memory leak of iterations in large hash.
mjc <mjcohen@[EMAIL PR  2008-03-18 12:56:51 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-19 07:13:28 
Re: Memory leak of iterations in large hash.
gazelle@[EMAIL PROTECTED]  2008-03-19 14:31:33 
Re: Memory leak of iterations in large hash.
iaminsik <iaminsik@[EM  2008-03-24 21:02:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:37:01 CDT 2008.