473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Object Hash of Contents

What is the fastest way to get the 'hash' (or CRC32 or whatever) of the
contents of an object

i don't care what's inside, I just want the 'hash' of its contents

(not to mixed with object.GetHashCode() which gives a hash code of an
instance, I want the hash of the data contents)

Evan
Aug 31 '07 #1
5 2952
Evan Camilleri wrote:
What is the fastest way to get the 'hash' (or CRC32 or whatever) of the
contents of an object
In both of your questions, you are overloooking a critical detail: there
is no consistent definition of an object's "contents".

You can come the closest, IMHO, for objects that can be serialized.
Then you can serialize them and use the resulting stream of data
(whether it's XML or binary) for your purposes.

But not all objects can be serialized, and unless you're talking about a
struct or class that only has value-type fields as data, there's not a
single block of data that represents the object.

If you can define "contents" in a way that allows you to address your
first question ("memory stream"), then the answer to the second ("hash")
can be discussed (though I think that answering "fastest" is
problematic, since any hash is going to have tradeoffs with respect to
speed versus how you intend to use it...the method that's truly
"fastest" may not work for your purposes).

Without a better definition and criteria for how you want to do this, I
don't think it's really possible to answer your question in a reasonable
way.

Pete
Aug 31 '07 #2
AFAIK

MD5 Hash is fast and pretty reliable for its purpose CRC is more reliable
but also much slower

MD5 hash is often used to quickly compare 2 binary`s ( are they the same or
not , idea; for update/ file synchronization programs etc etc )
CRC is often used by compression program`s ( winzip , winrar etc etc ) to
check if they are exactly the same on byte level ( to check if the file not
has gone corrupted during deflation )

HTH

Michel

"Evan Camilleri" <ev**@holisticrd.com.nospamschreef in bericht
news:%2******************@TK2MSFTNGP04.phx.gbl...
What is the fastest way to get the 'hash' (or CRC32 or whatever) of the
contents of an object

i don't care what's inside, I just want the 'hash' of its contents

(not to mixed with object.GetHashCode() which gives a hash code of an
instance, I want the hash of the data contents)

Evan

Sep 1 '07 #3
Michel Posseth [MCP] <MS**@posseth.comwrote:
Strange ,,,,
Just one week ago , i was asked to create a network file synchronization
mechanism wich did not care about file versions
"file remote different as the local version , copy it local" as we are
talking about hundreds of files and a total size of + 100 MB
i needed a fast way to check these files .

So i went digging on the web wich algorythm would be the fastest and found
my previous conclusion on various websites

My project is finished and performs superb , but you are telling me now that
CRC ought to be faster but less reliable ??
It *may* be faster, depending on the exact implementation. However,
it's unlikely that the hash performance is going to be significant
compared with the IO cost. Hashing 100MB of data is likely to be very
quick with either algorithm.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 2 '07 #4
>However,
it's unlikely that the hash performance is going to be significant
compared with the IO cost.
Yes ... that is a good one .. in my situation the cost of copying a file
that did not need replacement

However it seems that i got my implentation right as MD5 hash would be more
reliable but probably a bit slower as a CRC
and in my situation it turned out thet this is exactly what i need cause it
is more costly to copy the file over the intranet to the client

So i guess i had a lucky day when i wrote it :-)

regards

And thanks for sharing

Michel

"Jon Skeet [C# MVP]" <sk***@pobox.comschreef in bericht
news:MP*********************@msnews.microsoft.com. ..
Michel Posseth [MCP] <MS**@posseth.comwrote:
>Strange ,,,,
Just one week ago , i was asked to create a network file synchronization
mechanism wich did not care about file versions
"file remote different as the local version , copy it local" as we are
talking about hundreds of files and a total size of + 100 MB
i needed a fast way to check these files .

So i went digging on the web wich algorythm would be the fastest and
found
my previous conclusion on various websites

My project is finished and performs superb , but you are telling me now
that
CRC ought to be faster but less reliable ??

It *may* be faster, depending on the exact implementation. However,
it's unlikely that the hash performance is going to be significant
compared with the IO cost. Hashing 100MB of data is likely to be very
quick with either algorithm.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Sep 2 '07 #5
On Sep 4, 3:29 pm, "Evan Camilleri" <e...@holisticrd.com.nospam>
wrote:
I actually wanted to see some code since I cannot find how to get MD5 or CRC
for the object's data
As Peter said, there's no such concept as "the object's data" that
makes taking an MD5 hash sensible in all cases.

What would the MD5 of a NetworkStream be? Would you have to read all
its contents to find out?

Jon

Sep 4 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Clemens Hoffmann | last post by:
Hello, i have a nasty problem with object identity in hash tables. I try to use different objects as keys. It failed bacause i cannot identify object propperly. Different objects with the same...
1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
2
by: Peter Nofelt | last post by:
Hey all, I am running into an issue. My situation is that I wish to copy the contents of one listbox to an array, sort it by innerText value, and write the sorted options into a new listbox. ...
7
by: ajm | last post by:
Hi All, given an object file is there any way (or tool) to determine which compiler created it ? tia, A.
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
5
by: Michael H | last post by:
Hi all, I guess I don't fully understand how a SHA1 hash value is calculated in C# / .NET for a large file... I'm trying to calculate SHA1 values for large files that are much larger than my...
6
by: barcaroller | last post by:
I'm looking for a hash function (in C) that will convert a string of arbitrary length (but less than 1024 chars) to a reasonably-unique 16-bit short integer. Can anyone point me to such a hash...
11
by: Stephan Keil | last post by:
Hi all, I am a novice with .NET and I am wondering if there is something like an "identity value" of an object. I mean something like the object's address in C++ or C, i.e. a fixed unique value...
4
by: Evan Camilleri | last post by:
What is the fastest way to get the 'hash' (or CRC32 or whatever) of the contents of an object i don't care what's inside, I just want the 'hash' of its contents (not to mixed with...
3
by: Al Meadows | last post by:
I'm using a generic Dictionary object where it is described as: Dictionary<this, thatstuff = new Dictonary<this, that>() Where THIS is a class with several property values. This works fine...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.