On Sat, Aug 29, 2009 at 21:12, Uri Guttman<u...@stemsystems.com> wrote:
snip
>  SB> ... in my case, it's not feasible given that I need an object maintained,
>  SB> that is relatively complex in nature.
>
> you would be surprised at how much data you can put in a hidden
> variable. just convert it to text with dumper and store it there. html
> forms can send tons of data.
snip

If the data is sensitive, you don't want to transmit it in this way.

snip
snip
>  SB> Understood. Rephrased: I want to keep data alive in some fashion, *in
>  SB> memory* between processes.
>
> that is your bugaboo. can't be done. period. memory only exists inside a
> process on typical OS's. so stop thinking like that as it is the XY
> problem again. your problem is persistant data between processes but you
> think it is persistant data in ram between processes. you are caught up
> in a solution direction and painting yourself into a corner.
snip

What?  This is what shared memory is for.  It is available on all
modern UNIXes, and I think it might be available on Win32.  There are
modules in CPAN that make it easy to use:

#!/usr/bin/perl

use strict;
use warnings;

use IPC::ShareLite;
use Storable qw/thaw freeze/;
use Data::Dumper;

my $fetch = @ARGV;
my $key   = shift || $$;

my $share = IPC::ShareLite->new(
        -key     => $key,
        -create  => "yes",
        -destroy => 0,
) or die "coud not get shared memory: $!";

if ($fetch) {
        my $hash = thaw($share->fetch);
        print Dumper $hash;
        $share->destroy(1);
        exit;
}

print "$key\n";

$share->store(
        freeze(
                {
                        foo => {
                                foo => 1,
                                bar => 1,
                                baz => 1,
                        },
                        bar => {
                                foo => 1,
                                bar => 1,
                                baz => 1,
                        },
                        baz => {
                                foo => 1,
                                bar => 1,
                                baz => 1,
                        },
                }
        )
);

The first time you run it, pass no arguments in.  It will print out a
key for you to pass in the second time.

And even if you don't use shared memory, there are lots of in memory
databases such as memcached that are easy to use.  There is no need to
resort to slow disk if you need fast memory.

snip
>  SB> I'll use the info that I've been given to solve my current _issue_, and
>  SB> focus my time on the fundamentals. I'll try to stick with what can't hurt
>  SB> me if I 'leak' on it until I gain more experience...
>
> change the issue away from persistance in ram as it is not
> possible. think about it, who would OWN the ram? ram is allocated in
> a processes virtual space so how could it live outside a process? you
> don't want to have kernel space as that would be a security hole. shared
> memory is always backed by disk store as well so it is never just in
> ram.
snip

Okay, maybe I am exposing my ignorance, but I have never heard of
shared memory being backed by disk.  The whole purpose of shared
memory is to allow multiple processes to access the same chunk of RAM.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to