I run my php script and all I get is a blank screen (I dont mind waiting 10-30minutes even) and then I get an out of memory error.

Now can I increase the memory used by php to unlimited? and even so will I still get the out of memory error?

Do I need to change software (java, etc) to run this code?

Thanks, Regards X

PS: Its a script that contains millions of calculations hence the large use of memory.

Depends on what you are doing. What are you doing?
Can you post some of the code?

I havent started as yet.

Just writting some sample code of what I thought I would need and it requires alot of memory.

-5nested for loops with 50 loops each 50^5
-all the output from the for loops go through 50 if statements
-then final output

Get the idea?

:-O :-O :-O :-O :-O :-O :-O :-O :-O :-O :-O
DAMN!!!!!!
I'll put something together that does something like that and see if it works, either way I'll post my results. If it doesn't, I'll play around with it till it does and give you some advice.

5 minutes and still going.

The first time I ran it, of course it timed out in 30 seconds before I started using set_time_limit, I got this output:
done
vars =
outer = 0
mid = 0
inner = 70711

meaning the inner loop only went just over 70000, who knows how long this is going to take. :D

Coming up on 25 minutes. Wish there was a way to determine where it was in the process. Guess I could be using OB, maybe, but I didn't think of that.

Still rollin an hour later. Wheeeeeeeeew

commented: ;) Dude! You really have alot of patience! lol.. +7

hahaha

I appericate the hard work!!!

It may take hours, but the error I get eveytime is memory out of use.

Maybe because on each iteration of the for loop I assign the value to an array?

post your code. There are some minute things that people don't think about sometimes, like function calls that can cause this. If you pass a variable or array normally, it is then duplicated in the function, if you pass it be reference the function uses the original variable memory address. There are some other things you want to look out for too, you probably want to google, "php memory use" or something like that. By the way, the script is still going and I'm doing it more out of my own curiosity more than anything else.

So my pc had eventually froze up some time last night. I did some calculations and:
(312500000(per loop) * 5(loops) * 50(loops)) / 140000(loops per min) = 558035.7(minutes)

dude that's over a year!!!
That's on my machine
winXP/3.0 G(Dual Threaded) P/1 G Ram

I recommend finding a different solution

Here's my code

<?
$innerloop = 312500000;
$midloop = 50;
$outerloop = 5;
$output = "";
$test = 0;
register_shutdown_function("output");

for($i = 0; $i < $outerloop; $i++)
{
	for($x = 0; $x < $midloop; $x++)
	{
		for($y = 0; $y < $innerloop; $y++)
		{
			set_time_limit(30);
			
			for($u = 0; $u < 17; $u++)
			{
				if($i == $test)
				{
					$test *= $i;
					$output .= "red";
				}
				if($x == $test)
				{
					$test *= $x;
					$output .= "green";
				}
				if($y == $test)
				{
					$test *= $y;
					$output .= "blue";
				}
			}
		}
	}
}

function output()
{
	global $i;
	global $x;
	global $y;
	echo "done<br />".
	"vars = <br />".
	"outer = " . $i . "<br />".
	"mid = " . $x . "<br />".
	"inner = " . $y;
}
?>

I tried.

Very nice!

Looks something like the idea I have.

So you never got output I gather?

Ok well if I have a problem like this how can I do it?

Any ideas?

Thanks

I did some quick calculations I think it worked out to be 8 million possible combinations.

How long would that take to calculate using the for loops?

C++ is probably as fast as you're going to get, you can view the comparison to PHP here, comes out to about 90 times faster:
http://www.janitha.com/archives/38

Even then we're talking about something like 4 days. My PC wouldn't even last through the night, but it is only 3g single core. I'm not saying it isn't possible, of course it is, you just need a better processor than I have, and start thinking about making this a quintuple-threaded application. Meaning you trigger each thread(outer loop) simultaneously and calculate the output when they all return back.

commented: Went out of his own way to help me more than required, thankyou. +1

Thanks for your help so much Rob, its much appericated.

So C++ is the way to go even over java, etc?

You wouldnt have a page that compares them all by chance?

Thanks Aagain, Regards X

More accurate figures...

I have 8.5 million combinations which are then put through 30 if statements.

Then final output.

Now I havent tried this yet BUT I dont think php will let me make a 8.5 million length array nor will C++.

So what can I do?

PS: Best programming language is C++, correct?

Ya, I believe C++ would be the way to go, though Java may be a good choice as well. its not going to be a web app with C++ though, it will be a desktop app with an executable file. With Java you could stick it on the web. Either way they are both compiled prior to run time which is why they are much faster.

What are you doing with this array, could you possibly store the data in a database instead to limit the amount of memory storage?

By the way, I think something was really taxing my pc at the time that I ran that script because I am now putting through about 600000 loops per minute. Not that it really makes that big of a difference though, when you are talking about numbers that large. But that makes it much more of a possibility with a language like C++ or Java.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.