String interning when string caching is disabled

BrettShearerBrettShearer Posts: 5
edited October 26, 2012 2:58AM in SmartAssembly
Hi - I assume that the following method is the code that extracts the encoded/compressed resource strings or strings in general.

I can see that this is interning the result string (str2). If this is the case, why is the static hashtable required.

public static string Get(int #05b)
{
#05b -= #Z5b;
if (#Y5b)
{
string str = (string) #z5b[#05b];
if (str != null)
{
return str;
}
}
int count = 0;
int index = #05b;
int num3 = #Xp[index++];
if ((num3 & 0x80) == 0)
{
count = num3;
if (count == 0)
{
return string.Empty;
}
}
else if ((num3 & 0x40) == 0)
{
count = ((num3 & 0x3f) << 8) + #Xp[index++];
}
else
{
count = ((((num3 & 0x1f) << 0x18) + (#Xp[index++] << 0x10)) + (#Xp[index++] << 8)) + #Xp[index++];
}
try
{
byte[] bytes = Convert.FromBase64String(Encoding.UTF8.GetString(#Xp, index, count));
string str2 = string.Intern(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
if (#Y5b)
{
try
{
#z5b.Add(#05b, str2);
}
catch
{
}
}
return str2;
}
catch
{
return null;
}
}

Comments

  • The hashtable is used to look up decoded strings to save decoding everything every time you reference one. The interning, I believe, just helps the performance of this.

    Was there a specific reason you were asking?
    Systems Software Engineer

    Redgate Software

  • Just checking as I have long running services where interning may take too much memory (I am hosting applications and have about 300 running on one machine). Interning may impact memory use for me.
  • Ah, okay- it's all related to the "I want to cache strings..." option so turning that off may be worth trying to see if it helps in your scenario.
    Systems Software Engineer

    Redgate Software

Sign In or Register to comment.