Storing and Retrieving Number String/Array

Reply

Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Storing and Retrieving Number String/Array

 
0
  #11
Jun 18th, 2008
Try changing
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)
in php.ini .
Btw, I am not really sure if this will work !
Last edited by nav33n; Jun 18th, 2008 at 8:29 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Storing and Retrieving Number String/Array

 
1
  #12
Jun 18th, 2008
134217728 bytes is exactly the same as 128 megabyte. So how much memory does your computer have?
Perhaps you have an endless loop somewhere in your code. Could you post the code that causes this error?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 612
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #13
Jun 18th, 2008
LOL, I just checked my memory it is at 128MB (hence 134217728 bytes)

This is just for localhost at the moment so im not too worried if it cant work on the internet, its more for a home requirement for now.

It is just a loop that declares arrays and I think it declares too many but I need it to declare an x amount.

its like:

  1. for($i=0;$i<999999999999;$i++) {
  2. for($i=0;$i<999999999999;$i++) {
  3. $alpha[] = --$i . " " . $i . " " . ++$i;
  4. }
  5. }

Now I dont know how many times each loop goes for, depends on the requirements but it is ALOT so I dont know what to do at the moment?

Also on the 128MB thing what happens if I changed it to 99999.

Will the calculation work at the risk of blowing up my computer? or just freezing IE?

Thanks, Regards X
Last edited by OmniX; Jun 18th, 2008 at 8:58 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Storing and Retrieving Number String/Array

 
0
  #14
Jun 18th, 2008
Originally Posted by OmniX View Post
LOL, I just checked mine it is at 128MB
I thought so

Originally Posted by OmniX View Post

Now I dont know how many times each loop goes for, depends on the requirements but it is ALOT so I dont know what to do at the moment?
How about storing everything in a file or database instead of in memory ?

Originally Posted by OmniX View Post
Also on the 128MB thing what happens if I changed it to 99999.

Will the calculation work at the risk of blowing up my computer? or just freezing IE?
You computer is fine (with windows 2000 or better. (or linux).

With 99999 the code will still crash:

Each string is 5 bytes (1 byte for each character)
the inner loop loops 99.999 times.
The outher loop also
So memory required (in MB) == ((99.999 * 99.999 * 5) /1024) /1024 = 9536 MB
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Storing and Retrieving Number String/Array

 
0
  #15
Jun 18th, 2008
lol..You can increase the execution time limit, by either changing max_execution_time to 0 (in php.ini ) or use set_time_limit(0); in your script.

Ignore this post !
for($i=0;$i<999999999999;$i++) {
for($i=0;$i<999999999999;$i++) {
$alpha[] = --$i . " " . $i . " " . ++$i;
}
}
This will crash your browser anyway
Last edited by nav33n; Jun 18th, 2008 at 9:10 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 612
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #16
Jun 18th, 2008
Well a family friend has told me to construct a program on vary vague requirements.

But it requires at least 5 nested for loops and the iterations come out to something like intializing like 1mil plus arrays but by the end the script it removes like 800,000 of them.

So is this just not possible with php?
Do I have to pass it onto java or learn it myself?

Any possible fixes? Thanks

PS: can I increase "max_execution_time = 30"? Dosent seem to be working when I change the value to like 60/120.
Last edited by OmniX; Jun 18th, 2008 at 9:30 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Storing and Retrieving Number String/Array

 
0
  #17
Jun 18th, 2008
Initializing 1.000.000 arrays shouldn't be a problem (as long as they aren't bigger then 134 bytes), but what you asked:
  1. for (0 to 99.999)
  2. for (0 to 99.999)
will result in 99.999 * 99.999 loops, which is something like 10.000.000.000 loops.

So the answer is: yes, a million arrays in the memory are possible
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 612
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Storing and Retrieving Number String/Array

 
0
  #18
Jun 18th, 2008
so what is the max? (just so I can have an idea)
Last edited by OmniX; Jun 18th, 2008 at 9:32 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Storing and Retrieving Number String/Array

 
1
  #19
Jun 18th, 2008
Depends on how big your array is.

Let's say that the string in the array looks like this: 1 2 3 In theory this requires 5 bytes of memory. (3 numbers and two spaces)
(NOTE: I don't know exactly how PHP memory works with memory, so it might also be 6 bytes as in C and C++, where the last byte represents an 'end of string' character)

so you have 128 MB of memory, but you want to keep some of that available for other programs like windows etc. So let's say we can use half of it == 64 MB. That would lead to the following calculation:
(64*1024^2) / 5 = 13.421.772 elements for your array.

So to keep it on the safe side: max = 10 million
Last edited by niek_e; Jun 18th, 2008 at 9:40 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Storing and Retrieving Number String/Array

 
0
  #20
Jun 18th, 2008
Likewise, I recommend writing to a file or a db and then reading the data back into an array when needed. What do you need a million arrays for? This program sounds like a major resource hog, I would probably try to find another way of doing things.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC