{"id":4232,"date":"2014-03-30T09:24:53","date_gmt":"2014-03-30T09:24:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/comparing-data-bytewise-in-a-effective-way-with-c-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:24:53","modified_gmt":"2014-03-30T09:24:53","slug":"comparing-data-bytewise-in-a-effective-way-with-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/comparing-data-bytewise-in-a-effective-way-with-c-collection-of-common-programming-errors\/","title":{"rendered":"Comparing data bytewise in a effective way (with C++)-Collection of common programming errors"},"content":{"rendered":"<p>Is there a more effective way to compare data bytewise than using the comparison operator of the C++ list container?<\/p>\n<p>I have to compare [large? 10\u00a0kByte &lt; size &lt; 500\u00a0kByte] amounts of data bytewise, to verify the integrity of external storage devices.<\/p>\n<p>Therefore I read files bytewise and store the values in a list of unsigned chars. The recources of this list are handled by a shared_ptr, so that I can pass it around in the program without the need to worry about the size of the list<\/p>\n<pre><code>typedef boost::shared_ptr&lt; list&lt; unsigned char &gt; &gt; = contentPtr;\nnamespace boost::filesystem = fs;\n\ncontentPtr GetContent( fs::path filePath ){\n contentPtr actualContent (new list&lt; unsigned char &gt; );       \n \/\/ Read the file with a stream, put read values into actual content\nreturn actualContent;\n<\/code><\/pre>\n<p>This is done twice, because there&#8217;re always two copies of the file. The content of these two files has to be compared, and throw an exception if a mismatch is found<\/p>\n<pre><code>void CompareContent() throw( NotMatchingException() ){\n \/\/ this part is very fast, below 50ms\n contentPtr contentA = GetContent(\"\/fileA\");\n contentPtr contentB = GetContent(\"\/fileB\");\n \/\/ the next part takes about 2secs with a file size of ~64kByte\n if( *contentA != *contentB )\n      throw( NotMatchingException() );\n}\n<\/code><\/pre>\n<p><strong>My problem is this:<\/strong><br \/>\nWith increasing file size, the comparison of the lists gets very slow. Working with file sizes of about 100\u00a0kByte, it will take up to two seconds to compare the content. Increasing and decreasing with the file size&#8230;.<\/p>\n<p>Is there a more effective way of doing this comparison? Is it a problem of the used container?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is there a more effective way to compare data bytewise than using the comparison operator of the C++ list container? I have to compare [large? 10\u00a0kByte &lt; size &lt; 500\u00a0kByte] amounts of data bytewise, to verify the integrity of external storage devices. Therefore I read files bytewise and store the values in a list of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4232","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4232"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4232\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}