Length of shared data exceeds shared segment size- getting this error in perl code

Viewed 121

I am getting the error- "Length of shared data exceeds shared segment size" in my perl code when I am trying to read a csv file and load its contents into a shared variable. I am using the below code-

use IPC::Shareable;
my %options = (
    create    => 1,
    exclusive => 0,
    mode      => 0666,
    destroy   => 1,
);
my $handle = tie $arr_share, 'IPC::Shareable', $glue, { %options } or
    die "server: tie failed\n";

The CSV file is over 20 mega bytes. I have also tried defining size = 'some value', but it didnt work. Please suggest.

Thanks

1 Answers

This error indicates that your data structure is too large for the provided size option.

When modified, the entire data structure is serialized using Storable. This serialization must fit in the shared memory block whose size is controlled by the size option. (The default size is 1 KiB.) A 20 MiB CSV could easily require 500 MiB of shared memory.

Which begs the question... Does it make sense for your code to create a 500 MiB string every time a change is made? How about parsing a 500 MiB string every time data is fetched? This might not be the best approach for you.

Related