Slashdot Mirror


More Effective Use of Shared Memory on Linux

An anonymous reader writes "Making effective use of shared memory in high-level languages such as C++ is not straightforward, but it is possible to overcome the inherent difficulties. This article describes, and includes sample code for, two C++ design patterns that use shared memory on Linux in interesting ways and open the door for more efficient interprocess communication."

3 of 280 comments (clear)

  1. Memory Cache by GoodOmens · · Score: 1, Offtopic
    For those interested the livejournal people released a while ago their source code for memory cache.

    Imemcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

  2. Re:C++ has bigger memory issues by LarsWestergren · · Score: 1, Offtopic

    Java, in which everything is an object except for primitives and it takes ten classes and wrappers just to read a file,

    Eh?

    File inputFile = new File("temp.txt");
    FileReader in = new FileReader(inputFile);

    Or if you want to use the new IO library from 1.4 which gives you memory mapping and locking on sections of files,

    FileChannel in = new FileInputStream("temp.txt").getChannel();

    --

    Being bitter is drinking poison and hoping someone else will die

  3. PHP Shared Memory by GreySkull · · Score: 1, Offtopic

    Hi!
    I have a prob with shared memory in PHP and C++ I thought the /. crowd would help me...

    I have a server written in C++ and my webpages are in PHP. The PHP has to communicate with the server using shared memory. This was working fine on the server running FC-1 with php-4.3.8. We recently migrated to CentOS 4.1 (Equivalent to RHEL 4.1) running php-4.3.9. The error it displays is as follows:

    shmop_open(): unable to attach or create shared memory segment in /var/www/html/sharedmem.php on line 2

    The server opens the shm in 666 (originally was 644) even then it was not working. I can see the shared mem open using 'ipcs' command.

    The source code of PHP is as follows:

    "; // These are fine

    # print $shm_key;

    $shm_id = shmop_open($shm_key, "a",0,0) or die("FATAL ERROR:: Unable to Access Shared Memory"); /*$shm_size = shmop_size($shm_id);
    DEBUG:: print ("Shared Memory Block Size: " . $shm_size."\n");
    */ // Now lets read the string back
    $data = shmop_read($shm_id, 0, $shm_size);
    if (!$data) {
    echo "FATAL ERROR:: Couldn't read from shared memory\n";
    exit;
    }
    ?>

    Both the configs say that 'shmop' is enabled.

    Can some one help me with this, I am in desperate need of this, if this fails I might have to search for an alternative and the project has to go live in a week or so. I am in desperate need of help, can any one help pls?

    Regards,
    Yaswanth