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

Re: IPC::ShareLite - getting a shares size

by zentara (Archbishop)
on May 17, 2012 at 20:16 UTC ( [id://971167]=note: print w/replies, xml ) Need Help??


in reply to IPC::ShareLite - getting a shares size

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

Replies are listed 'Best First'.
Re^2: IPC::ShareLite - getting a shares size
by tomfahle (Priest) on May 17, 2012 at 20:56 UTC

    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: note [id://971167]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found