On Sat, Aug 29, 2009 at 23:21, Uri Guttman<u...@stemsystems.com> wrote: >>>>>> "CO" == Chas Owens <chas.ow...@gmail.com> writes: > > CO> On Sat, Aug 29, 2009 at 21:12, Uri Guttman<u...@stemsystems.com> wrote: > CO> 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. > CO> snip > > CO> If the data is sensitive, you don't want to transmit it in this way. > > you can use shttp and send anything. cookies are better but it would work. snip
I don't mean eavesdroppers, I mean the client should not be able to see the data. Never send data to the client they should not have. Encrypting the data (apart from https, which only encrypts the transfer of the data) might be good, but that is extra work. And why transmit anything to the client that the client doesn't need? snip > CO> What? This is what shared memory is for. It is available on all > CO> modern UNIXes, and I think it might be available on Win32. There are > CO> modules in CPAN that make it easy to use: > > it isn't shared except between processes or on disk. he specifically > asked about shared ram that stays resident outside of processes. snip Shared memory is external to any process. No process needs to be running for it to exist. Did you look at the code sample? You run the program the first time and it creates a chunk of shared memory, prints out a key that lets you get back to that memory, puts some stuff in it, then exits. No process is running at this point. Then you run the program again with the key given by the first run, it access the memory, prints the contents, then destroys the memory (because otherwise it will keep existing until you reboot). snip > CO> Okay, maybe I am exposing my ignorance, but I have never heard of > CO> shared memory being backed by disk. The whole purpose of shared > CO> memory is to allow multiple processes to access the same chunk of RAM. > > lower level stuff works that way. you can mmap in a file into a process > and so can other processes at the same time. all writes to the mapped > virtual ram will be backed by disk so it is persistant. of course you > still need to deal with locking and such. it wouldn't work in perl > easily due to memory not being fixed in virtual space as perl can > realloc as it wants to. this is easily done in c. snip mmap is not shared memory; it is a modern alternative to shared memory. The two big differences are the ability (not the requirement) to have the memory backed by a file (it is often used to read files more efficiently) and that the memory does not outlive the process. Shared memory on the other hand is just a chunk of memory with a name that can be used by processes that know its name. It is persistent. If your code doesn't clean up after itself, the memory will stay allocated until the machine reboots. I lost about 300 bytes of memory to bad code (I forgot to print the key the first time, and a couple other things went wrong that I don't remember) while writing the example. I won't get that memory back until I reboot. This points to a big danger to using shared memory. If you screw up you have real memory leaks that can only be fixed by rebooting. You must serialize your data before you store it in shared memory as Perl won't just use it. At that point it is just a matter of making the shared memory segment the right size. And, as you can see for my example in an earlier email, there are modules that take care of that work for you. I would have used IPC::SharedCache, but it failed its tests on my machine, so I dropped back a layer. IPC::SharedCache takes care of the serialization step for you and provides a nice tied hash. -- 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/