Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Unpacking and converting

by andal (Friar)
on Mar 10, 2011 at 12:47 UTC ( #892398=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Unpacking and converting
in thread Unpacking and converting

For consistency sake though, I'd like to mention that conversion from text to number does indeed add compactness to serialized data. I fail to understand why so many people are insistent on ignoring the obvious.

You fail to understand it because you don't understand what is "serialized data" and what is "conversion from text to number". Serialized data is something stored in sequential area (file, memory chunk etc.) The "conversion" is something that is done at run time to provide context specific information. Perl does the conversion internally and automatically and you normally don't need to think about it. Conversion to or from numbers does not necessary save any RAM, since you don't know if the perl has discarded the string buffer, or keeps it around for the sake of speed optimization when the string is needed again.

The "serialization" is needed when you copy the data from perl into file (for example). In this case, to save space you may use function "pack". Here's the piece of code that stores '00000001' as single character in the file.

print FILE pack('C', '00000001');
Again, perl converts from string to number automatically and stores in the buffer single byte with value 1.

I hope this clarifies for you why explicit conversion from string to number is a nonsense in general. Though it might be needed in certain cases, but definitely not for decreasing RAM usage :)


Comment on Re^5: Unpacking and converting
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-09-21 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls