Re: IPC::Shareable Problem with multidimentional hash



Sébastien_Cottalorda <scottalorda@xxxxxxxxxxx> wrote:
> xhoster@xxxxxxxxx wrote:
> > Sébastien_Cottalorda <scottalordaNOSPAM@xxxxxxxxxxx> wrote:
> >
> >>Hi all,
> >>
> >>I need to use that kind of shared hash:
> >>%shared_hash = (
> >> '123456' => {
> >> 'bla' => 123,
> >> 'bli' => 465,
> >> ect ...
> >> },
> >> ect ...
> >>);
> >>
> >>with about 500 primary keys.
> >>When I "feed" the %shared_hash, I note that the system create as many
> >>shared segment and semaphore than there are primary keys.
> >
> >
> > Yes. This fact is documented.
>
> Where ... ?
> I understand limits but not the manner it stores datas like hashes.

It is not the hashes, it is the references to the hashes:

REFERENCES

When a reference to a non-tied scalar, hash, or array is assigned to a
tie()d variable, IPC::Shareable will attempt to tie() the thingy being
referenced[4] ....
Secondly, since a new shared memory segment is created for each thingy
being referenced, the liberal use of references could cause the system to
approach its limit for the total number of shared memory segments allowed.



> >
> > You could try using Storable or Data::Dumper to collapse the inner
> > structures into flat strings for storage.
> >
> > Xho
>
> I've read, re-read, re-re-read the perldoc IPC::Shareable : It seems to
> already use Storable to store hash structure.

It uses Storable to store the top level hash structure. It also uses
Storable to store each sub-hash too, but it does each of those in a
different shmem segment. If you preemptively use Storable on the inner
hashes, so that they are just strings and not hashrefs by the time they get
stuck in the main hash, then IPC::Shareable would just store them as
strings in the main shmem segment.

>
> Concerning Data::Dumper, I don't understand anything (maybe it's me ;-) )
> I don't understand how I can use that module to store and manipulate
> hash of hash in a share structure.

You use Data::Dumper the same way you use Storable, but the thawing is
more awkward.

> If you have an exemple, I'll apreciate a lot.

It ain't pretty, but I don't think using shared memory ever is pretty.


my ($i,$j);
for $i (1 .. 300){
my %x;
for $j (1..3){
$x{$j} = "fall";
}
$colours{$i} = freeze \%x;
}
print "Charged - Press a key to continue -\n";
my $e=<STDIN>;
foreach $i ( keys %colours){
print "$i => \n";
my $x=thaw $colurs{$i};
foreach $j (keys %$x){
print " $x{$j}\n";
}
}
exit;

Note that this won't be very fast, because it is freezing and thawing the
entire data structure just to access one part of it. I suspect that that
is why Shareable was implemented the way it was (using seperate segments
for each piece) in the first place.

Shared memory is not one of the hard things which Perl has made easy.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages

  • Re: References as hash keys (Srinivasans "Advanced Perl Programming")?
    ... keys, you can, but if you need to dereference the references, you can't ... store the references only in the hash as keys unless you use the ... you need to store the ...
    (comp.lang.perl.misc)
  • Re: IPC::Shareable Problem with multidimentional hash
    ... shared segment and semaphore than there are primary keys. ... since a new shared memory segment is created for each thingy ... It uses Storable to store the top level hash structure. ...
    (comp.lang.perl.misc)
  • Re: storing a hash of a hash in a DBM database
    ... > I'm trying to store a hash of a hash in a DBM database, ... > running into problems with my references. ...
    (comp.lang.perl.misc)
  • Re: building Lighttpd 1.4.30 using gcc 4.4.6: ___builtin_stdarg_start referenced
    ... 1305 of lemon.c references va_start: ... and another hardlink from that over here: ... rpm's final go at installing 446 added: ... _buffer_init_string referenced from text segment ...
    (comp.os.os2.programmer.porting)
  • Re: dynamic structure for storing/querying intervals
    ... intervals on a line (or, in possibly degenerate cases, just points). ... I'd like to be able to query the structure by providing a range and retrieve all intervals which overlap the query range. ... While succeeding points are inside the search interval, store the points in some intermediate structure, sorted or hashed on their interval object references. ... segment, and moving up one level in the hierarchy you get a line segment that contains all its child segments, with references to the intervals that would otherwise be referenced by /all/ the children, and so on. ...
    (comp.programming)