Because this is a language problem, conventional solutions are more difficult to solve. Here is a solution through string.
$total = 100000;
$double = "";
for ($i = 0; $i < $total; $i++)
{
$double .= pack("d", $i + 0.1);
}
for ($i = 0; $i < $total; $i++)
{
unpack("@" . ($i * 8) . "/d", $double);
}
This example uses a string to save an array of doubles. Then unpack it when using it.
Of course, this will affect performance. It depends on the specific needs.
For example, in this case:
You have 10 arrays, each of which is 10M (about 1 million data), so ten will cost 100M memory.
If you add 10 people to concurrently, the memory will be seriously insufficient.
Then, in 10 arrays, not used at the same time. You can save them as string
Then, when used, unpack a string becomes an array.
Copy the codeThe code is as follows:
$total = 100000;
$double = "";
for ($i = 0; $i < $total; $i++)
{
$double .= pack("d", $i + 0.1);
}
for ($i = 0; $i < $total; $i++)
{
unpack("@" . ($i * 8) . "/d", $double);
}
This example uses a string to save an array of doubles. Then unpack it when using it.
Of course, this will affect performance. It depends on the specific needs.
For example, in this case:
You have 10 arrays, each of which is 10M (about 1 million data), so ten will cost 100M memory.
If you add 10 people to concurrently, the memory will be seriously insufficient.
Then, in 10 arrays, not used at the same time. You can save them as string
Then, when used, unpack a string becomes an array.