Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Eating RAM problem

by crenz (Priest)
on Aug 01, 2002 at 20:01 UTC ( [id://186914]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Eating RAM problem
in thread Eating RAM problem

Bytes always consist of 0's and 1's. ;-)

Frankly speaking, I am not sure I understand you here. Let me rephrase: For each block of n bytes, you are going to replace it by a number of m bytes; m>n. Your input data and output data are files consisting of 0's and 1's. I don't understand why, but I accept that. Is that correct?

If yes, you can perform any mathematical operations with any of the following three representations of the data:

  • A @list of bits, e.g. @list = (0, 1, 0, 0, 0, 0, 0, 1); # 'A'; this is what you are using.
  • A $bitstring, e.g. $bitstring = '01000001'; # 'A'.
  • Binary data, e.g. $data = 'A'; (that is, read directly from the file using e.g. $data = <file>). Obviously, this representation uses the least amount of space. This is not really a compression (for my definition of compression), it is just the 'natural' representation of the data. On the contrary, the other two representations are (probably unnecessary) expansions.

These three representations are equivalent; you just need to use different syntax to access them. For example, to access the third bit in the data, you would use

  • $third_bit = @list[2];
  • $third_bit = substr($bitstring, 2, 1);
  • $third_bit = vec($data, 5, 1); (this one is a bit more tricky, see the documentation for vec)

To access whole bytes or blocks of bytes, you would use splice, substr and substr, respectively. All the operations you will need to perform can be expressed in all three data representations -- but the last one will only use 2M of memory... Plus, for the last one, you can use perl's binary or, and etc, whereas for the @list and $bitstring, you'll have to emulate the mathematical functions (using the abovementioned substr, vec etc.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-25 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found