BrianP,

Maybe this helps?

use strict; use warnings; # my $file = '249465.pprgb-srgb.absv.4000.cs.jpg'; # Original + File downloaded my $file = '249465.pprgb-srgb.absv.4000.cs.jpg2'; # New File + multiple copies my $compraw = -s $file; my $pixels = int ( $compraw / 6 ); my @UINT48; $UINT48[$pixels] = ''; ## Allocate size of array ( faster ) open ( my $in, "<", "./$file") or die "$!\n"; if ( 1 ) { my $loc = -1; my $size = sysread( $in, my $buffer, $compraw ); # No bu +ffering if ( $size ne $compraw ) { die "Disk error: $!\n" } while( $buffer ) { $UINT48[$loc++] = substr( $buffer, 0, 6, '' ); } } close $in; ## $buffer is gone! ## @UINT48 is populated with 6 byte RG +B strings my $uint48 = scalar @UINT48; print "\nImage has $uint48 pixels\n"; ## How to get the values back! my ( $R,$G,$B ) = unpack( "SSS", $UINT48[0] ); print "\t$R,$G,$B\n"; ( $R,$G,$B ) = unpack( "SSS", $UINT48[$pixels] ); print "\t$R,$G,$B\n"; __END__ > time pyrperl uniqcolors.plx Image has 41473711 pixels 17994,17993,256 55551,57599,4096 real 0m13.745s user 0m12.905s sys 0m0.840s >
For you earlier question about reading from disk, Linux reads/writes in 4096 byte blocks. So I multiply the pagesize * 6 (since 4096 is not exactly divisible by 6). Use you system page size and multiply by a factor of 6 ( 6,12,...).

If you want '$buffer' around after the populate cycle, just remove the "if ( 1 ){ }" or define '$buffer' before the loop,

Regards...Ed

"Well done is better than well said." - Benjamin Franklin


In reply to Re: Perl Hashes in C? by flexvault
in thread Perl Hashes in C? by BrianP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.