Segmentation error with fixed array PHP 5.3.5

When trying to define such an array:

$array = new SPLFixedArray(256);

for ($i = 0; $i < 256; $i++) {
    $array[$i] = new SPLFixedArray(256);

    for ($j = 0; $j < 256; $j++) {
        $array[$i][$j] = new SPLFixedArray(5);

        for ($k = 0; $k < 5; $k++) {
            $array[$i][$j][$k] = 0;
        }
    }
}

I only get in the CLI, "Segmentation Fault". I read about such errors here on SO in C / C ++, where there is probably a memory problem and recommends loading everything into heap memory using malloc (). In PHP, do we have such a tool?

This happens even in small 3D arrays like 15 instead of 256 (but it works up to 15).

Thank!

+3
source share
3 answers

Only PHP error will be segfault; you can never do that. These are segfaults for me in PHP 5.3.5. I see nothing in 5.3.6 the change log, which indicates that it has been fixed. (He falls on 5.3.6 for me too.)

As a workaround, you can do this:

$array = new SplFixedArray(256 * 256 * 5);
$array[$i * JK + $j * K + $k] = $foo;

JK K - . JK = $jsize * $ksize; K = $ksize.

, , , 3D-.

Update:

PHP 5.3.7-dev, segfault. , , PHP 5.3.7.

+5

, PHP . , , SPLFixedArrays .

, , Linux Windows.

+1

, segfault , , . , , SplFixedArray(), . , , 3D-, .

At the same time, try not to have such nests, if possible. This is equivalent to infinite recursion. Not to mention that the underlying mechanism of PHP is still C.

Hope this helps! Hooray!

0
source

All Articles