Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 24th, 2006, 10:42 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Retaining Variables In Memory?

I tried searching this on google, but all I got was unrelated trash like how to upgrade your computer's RAM and such.

Is there a way to store a variable within one session of a page, and recall it at a later time? Keeping data inside the RAM? Without storing the value in a data file?

I don't think this is possible, or else I think I would have stumbled across it already. But it would be so perfect if it were. I will slap PHP across the face if it can't.
Sane is offline   Reply With Quote
Old Jul 24th, 2006, 10:56 PM   #2
Darkhack
Hobbyist Programmer
 
Darkhack's Avatar
 
Join Date: Dec 2005
Location: Kansas City
Posts: 102
Rep Power: 3 Darkhack is on a distinguished road
Send a message via AIM to Darkhack
There are SESSION and COOKIE variables if that is what you mean. I don't seem to exactly understand what your question is. Here are some links that might help.

http://www.w3schools.com/php/php_cookies.asp
http://www.w3schools.com/php/php_sessions.asp
Darkhack is offline   Reply With Quote
Old Jul 24th, 2006, 10:58 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
No, I mean like load an array of 100 random integers in to the RAM in page: "init.php", and then display them straight from the RAM on: "index.php". So then anyone seeing "index.php" would see the exact same thing... as long as "init.php" has been accessed at least once. Then every time "init.php" is accessed, it would cause a different result to show in "index.php".

Note: This is not actually what I'm doing. Just a demonstration of what it could be used for.
Sane is offline   Reply With Quote
Old Jul 24th, 2006, 11:19 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Not on your ordinary, modern, multiple-processed, controlled-by-an-OS-that-ain't you, memory-managed system, no.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 24th, 2006, 11:52 PM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 841
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Your best bet would probably be to write data to a temporary file, and load that in the subsequent page.
titaniumdecoy is offline   Reply With Quote
Old Jul 25th, 2006, 8:58 AM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Oh wow... so I think this really means that Python can sometimes be faster than PHP. Both in efficiency and production. If we were to do this in Python, it would be...

        ...

        @cherrypy.expose
        def init(self):
            self.random_ints = [str(random.randrange(10)) for i in range(100)]
        
        @cherrypy.expose
        def index(self):
            return '<br />'.join(self.random_ints)

        ...


And due to PHP not being able to do the same... there will be a dramatic loss in potential speed. The relevant data is going to be needlessly... loaded, parsed, modified, outputted, formatted, then saved... every time a page is accessed. That makes me sad.

*slaps PHP*
Sane is offline   Reply With Quote
Old Jul 25th, 2006, 9:19 AM   #7
Darkhack
Hobbyist Programmer
 
Darkhack's Avatar
 
Join Date: Dec 2005
Location: Kansas City
Posts: 102
Rep Power: 3 Darkhack is on a distinguished road
Send a message via AIM to Darkhack
I'm not a python guy but I doubt even Python stores it in RAM. If I understand this correctly you want to be able to load/generate data by visiting init.php but then have the same data be displayed to everyone on index.php.

You have to store it somewhere on the disk of the server. Either a database, flat-file, or something of the sort. Another possibility is to generate the entire html on the spot. When you visit init.php it will then generate a static html file called index.html that gets updated through init.php. The server will cache some popular pages in RAM although there is no way to force something to stay in RAM.
Darkhack is offline   Reply With Quote
Old Jul 25th, 2006, 11:53 AM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
No, Python definitely stores it in the RAM. The way Python works, is it is its own server. The HTTP server is embedded within your Python script. So the entire site, everything that can be seen and downloaded, is contained within (at least) one file. You're basically extending the server's capabilities to decide what pages are linked to what.

You don't need Apache to run it (although you can), all you need is one Python script and the necessary files that are used to embed the server (CherryPy). It most certainly is held inside the RAM, or else around 6000 pages on my website would not be working right now.

Since PHP can not do this, it's limiting a lot of potential speed ups in efficiency. PHP could get nowhere near the speed of Python+CherryPy in some situations.
Sane is offline   Reply With Quote
Old Jul 25th, 2006, 12:07 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Sounds like you're talking about an ability of CherryPy, not Python, per se. This is a question of a parent process treating all services as children and arranging for shared memory, I would guess.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 25th, 2006, 12:20 PM   #10
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Well, yes. I chose to ignore that fact. I would have hoped PHP had some way to communicate back to Apache to manage memory (PHP --> Apache --> PHP).

Not necessarily in the same manner Python does it (CherryPy --> Python --> CherryPy).
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
When to use the new keyword in C++? titaniumdecoy C++ 28 Mar 16th, 2006 12:36 PM
Dynamic memory - variables darkone916 C++ 4 Dec 7th, 2005 6:24 AM
Which area of memory does new use? aznluvsmc C++ 11 Nov 5th, 2005 7:37 AM
Pointers in C (Part II) Stack Overflow C 2 Apr 29th, 2005 10:39 AM
Pointers in C (Part I) Stack Overflow C 4 Apr 28th, 2005 7:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC