Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

IPC::ShareLite - getting a shares size

by Anonymous Monk
on May 17, 2012 at 19:36 UTC ( [id://971163]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

IPC::ShareLite documentation states that you can get a share's segment size:

my $size = $share->size;

but $share->size always returns 0.

Example:

use strict; use warnings; use IPC::ShareLite; use Storable qw( freeze thaw ); my $share; eval { $share = IPC::ShareLite->new( -key => 4812, -create => 'yes', -destroy => 'no', -mode => 0600, ); }; if ($@) { warn "Woops: $@"; exit; } # Let's use some memory my @array = 0 .. 1500000; $share->store( freeze( \@array ) ); my $size = $share->size; print "Size: $size\n"; my $num_segments = $share->num_segments; print "Segments: $num_segments\n";

which yields:

Size: 0
Segments: 207

Any hints are very appreciated.

Replies are listed 'Best First'.
Re: IPC::ShareLite - getting a shares size
by zentara (Archbishop) on May 17, 2012 at 20:16 UTC
    I'm not sure you are interpreting size correctly. It is not the total size of all the memory used, but the segment size you desire. You need to set the segment size in the constructor. You were leaving it as zero by default.
    #!/usr/bin/perl use strict; use warnings; use IPC::ShareLite; use Storable qw( freeze thaw ); # dosn't show segment size correctly without size set. my $share; eval { $share = IPC::ShareLite->new( -key => 4812, -create => 'yes', -destroy => 'no', -mode => 0600, -size => 5000 ); }; if ($@) { warn "Woops: $@"; exit; } # Let's use some memory my @array = (0 .. 1500000); $share->store( freeze( \@array ) ); my $size = $share->size; print "Size: $size\n"; my $num_segments = $share->num_segments; print "Segments: $num_segments\n"; my $usage = $share->size * $share->num_segments; print "Usage: $usage\n";

    OUTPUT:

    $ ./971163.pl Size: 5000 Segments: 207 Usage: 1035000

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Thank you. You made my day.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (None)
    As of 2024-04-25 00:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found