0
Guys, I’m opening here and I have the following problem: I created a function with a hint that I found right here in stackoverflow.
function DozenGenerate($game,$dozen) {
$this->game = $game;
$this->dozen = $dozen;
if ($game === 0) {
return array(array());
}
if (count($dozen) === 0) {
return array();
}
if (count($dozen)< $game){
}
ob_start();
$dozen_receive = $dozen[0];
$dozen_compare = array_slice($dozen,1,count($dozen)-1);
$dozenI = $this->DozenGenerate($game-1,$dozen_compare);
for ($i = 0; $i < count($dozenI);$i++){
array_splice($dozenI[$i],0,0,$dozen_receive);
}
ob_get_contents();
$dozenII = $this->DozenGenerate($game,$dozen_compare);
ob_end_flush();
return array_merge($dozenI,$dozenII);
}
Then I create a range and use the function:
$range = range(1,24);
$numbers = DozenGenerate(15,$range);
print_r($numbers);
When it generates very large unique combinations, it returns this error that would be natural:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 25165832 bytes) in C:\xampp\htdocs\netboloes\class\folk.php on line 44
I wanted to know how to do the memory emptying so that the function continues running, without returning this message and yes the array? I hope you can help me.
– Fernando Souza
Vlw Fernando by the tip. But in practice this would not be possible with the code running on a server, as it would not have access to php.ini directives...
– Alessandro Carvalho
Hello, you need this array for some future data processing or just to print on the screen as it is in the sample code?
– David Alves
In this case the array will be printed on the screen and will then be available for application of a series of filters
– Alessandro Carvalho
Do you have access to the database, so you can save this data from the array? Because if it were just for screen printing, I would have a very simple solution, but having to manipulate data, it is necessary bd
– David Alves
David is my question. This function can generate literally millions of indexes within an array. After generating all unique combinations, filters apply that will significantly reduce these indexes to then be saved by the user in the BD
– Alessandro Carvalho
Got it. Can the filtering process be done during the generation? Thus decreasing the array?
– David Alves
Unfortunately I did not see this possibility. This pq would generate an even greater delay in the return of the function. That’s why I opted for the filters application after the array generation.
– Alessandro Carvalho
Your recursion will always tend to consume all available memory. You’d better try some technique dynamic programming to reduce both the execution time (which I imagine to be enormous) and memory consumption.
– Juven_v
Could this problem be solved? I have the same problem when consuming Rbbitmq messages. There comes a time that gives this same error
– Vitor Daniel