HighTechTalks DotNet Forums  

Re: Fast deserialisation of strings from byte[]

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Re: Fast deserialisation of strings from byte[] in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
drewnoakes
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-05-2005 , 12:44 PM






Hi Cor,

Thanks for your prompt response. I'm aware of the behaviour of strings with
regards to mutability, but this issue is different. Perhaps I didn't explain
myself clearly enough. I simply do not want to instantiate two different
string objects that have the same value.

Therefore, when I'm stepping through the byte[], the first time I see a
given pattern I would create the string and store it. The next time I see
the same pattern, I'll return a reference to the string I have stored. This
avoids the overhead of having two strings on the heap that have identical
values.

Bear in mind that I'm talking about doing this many many times a second, to
a point where I believe there is a performance gain to be reaped from this
added complexity.

Regards,

Drew.

Reply With Quote
  #2  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-05-2005 , 01:09 PM






Drewnoakes,

This sounds to the hashtable (dictionary) however I doubt that it will be
giving you benefits.

The bytepatern in the key and the string in the value.

http://msdn.microsoft.com/library/de...ClassTopic.asp

I hope however that it helps anyhow.

Cor



Reply With Quote
  #3  
Old   
drewnoakes
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-05-2005 , 01:18 PM



Hi Cor,

If I use a Hashtable, I must create a new byte[] which in turn is another
object allocation. I wish to achieve this lookup without allocating any
object on the heap.

Drew.

Reply With Quote
  #4  
Old   
Cor Ligthert [MVP]
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-05-2005 , 01:57 PM



Drewnoakes,

Are you sure of that, the hashtable holds objects, not values.

http://msdn.microsoft.com/library/de...ssaddtopic.asp

I hope this helps,

Cor



Reply With Quote
  #5  
Old   
drewnoakes
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-06-2005 , 03:47 AM



Hi Cor,

Keying a hash table on byte[] will not reduce my memory overhead. Besides,
I still have to allocate an object (byte[] is an object, not a value-type)
before I can look up the string in the hashtable.

Drew.

Reply With Quote
  #6  
Old   
.neter
 
Posts: n/a

Default Re: Fast deserialisation of strings from byte[] - 09-06-2005 , 03:50 AM



Cor Ligthert [MVP] wrote:
Quote:
Drewnoakes,

Are you sure of that, the hashtable holds objects, not values.

http://msdn.microsoft.com/library/de...ssaddtopic.asp

I hope this helps,

Cor


Well, a raw byte[] cannot be used as a key. But you can calculate an
integer hash value for the byte sequence and use that hash as a key in a
normal Hashtable.
But as someone has previously said, this will not necessarily improve
the performance.

Best regards
RG


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.