Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: vec overflow?

by LanX (Canon)
on Jun 25, 2013 at 00:48 UTC ( #1040500=note: print w/ replies, xml ) Need Help??


in reply to vec overflow?

OFFSET is a signed integer and most Perl compilations restrict them to a maximum of 31 bits.

If you need a larger OFFSET you can switch to a 64 bit platform.

vec EXPR,OFFSET,BITS
               Treats the string in EXPR as a bit vector made up of elements
               of width BITS, and returns the value of the element specified
               by OFFSET as an unsigned integer. ...

Or just split the EXPR into smaller chunks and do basic arithmetics for calculating OFFSET.

Cheers Rolf

( addicted to the Perl Programming Language)

update

) doesn't help, according to BrowserUk

update

see older discussions and proposed workarounds

update

this workaround doesn't look efficient, since substr is an lvalue you can use constructs like

vec ( substr( $str, OFFSET_HIGH, 2**31), OFFSET_LOW, BITS ) = NEW

(well if substr allows OFFSETs that big ... can't test!)


Comment on Re: vec overflow?
Select or Download Code
Re^2: vec overflow?
by BrowserUk (Pope) on Jun 25, 2013 at 08:49 UTC
    this workaround doesn't look efficient

    It is. It takes an lvalue reference (a scalar value) and passes that to vec. It is marginally less efficient than vec( substr( ... ), ... );, but not so much that you would be able to detect it.

    However, substr can only provide an lvalue for byte-sized units; where vec can provide an lvalue for 8 byte units.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Ok, I had errors testing it out in the debugger, but turned out that just the automatic Data::Dump couldn't handle lvalues.

      Asa suggestion:

      I think using a foreach alias like shown in the docs for substr is a clearer alternative to lvalue-refs.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        I think using a foreach alias like shown in the docs for substr is a clearer alternative to lvalue-refs.

        Maybe, though I've been aware of LVALUE refs, and using them regularly, for a long time, but I've never seen a use of a for alias used that way until I followed your link to a newer set of docs than I have locally.

        Comparing:

        my $ref = \ substr( $astring, $start, $len ); vec( $$ref, $offset, $size ) = 1;

        To:

        vec( $_, $offset, $size ) = 1 for substr( $astring, $start, $len );

        The first one is very familiar (to me), whereas the latter just looks weird.

        The presence of \ and $$ref seem stronger clues than the $_ and for.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-07-23 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls