# IPC shared memory

**URL:** <https://discourse.processing.org/t/ipc-shared-memory/47791>\
**Category:** Libraries\
**Created:** [January 23, 2026, 9:48pm UTC](https://discourse.processing.org/t/ipc-shared-memory/47791 "2026-01-23T21:48:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![potato](https://avatars.discourse-cdn.com/v4/letter/p/a6a055/32.png) [@potato](https://discourse.processing.org/u/potato)\
**Post date:** [January 23, 2026, 9:48pm UTC](https://discourse.processing.org/t/ipc-shared-memory/47791/1 "2026-01-23T21:48:42Z")

</div>

Was looking for IPC shared memory examples for processing but didnt find any. Anyone used shared memory in processing or have a guide/ example for it?

Thanks

---

<div class="post-metadata">

**Author:** ![seanc4s](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@seanc4s](https://discourse.processing.org/u/seanc4s)\
**Post date:** [January 27, 2026, 3:23am UTC](https://discourse.processing.org/t/ipc-shared-memory/47791/2 "2026-01-27T03:23:35Z")

</div>

You can look up Java Memory Mapped Files. Even very high level Java programmers misunderstand those. I think because they don’t understand how operating systems actually handle paged memory.

I did some experiments and they are as fast as array memory. The assumption from people not understanding the OS too well is file acess=very slow. And also the clunky method access looks like it would be slow. However the hotspot compiler just optimizes away the method call so you are just left with a standard DRAM memory access.

---

<div class="post-metadata">

**Author:** ![seanc4s](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@seanc4s](https://discourse.processing.org/u/seanc4s)\
**Post date:** [January 27, 2026, 8:57am UTC](https://discourse.processing.org/t/ipc-shared-memory/47791/3 "2026-01-27T08:57:24Z")

</div>

Maybe something like this, not saying I’m an expert.

```auto
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.*;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
void setup() {
  int elements=25*1024*1024; // 100Mb of floats (4 bytes per float)
  try {
    File temp = Files.createTempFile("float-mmap", ".bin").toFile();
    temp.deleteOnExit();
    RandomAccessFile raf = new RandomAccessFile(temp, "rw");
    FileChannel fc = raf.getChannel();
    raf.setLength(elements*4); // ensure file size (4 bytes for each float)
    MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, elements*4);
    // make sure native order
    mbb.order(ByteOrder.nativeOrder());// Otherwise data in network order = slow
    FloatBuffer mapped = mbb.asFloatBuffer();

    // Fill mapped buffer data
    double sum = 0; // Use double to reduce round off error
    double sumMapped = 0; // Use double to reduce round off error
    for (int i = 0; i < elements; i++){
      sum+=i*1f;
      mapped.put(i, i * 1.0f);
    }
    for (int i = 0; i < mapped.capacity(); i++){
      sumMapped += mapped.get(i);
    }
    println(sum+" Mapped:"+sumMapped);
    raf.close();
    temp.delete();
  }catch(IOException e) {
    println(e);
  }
}

```

You can probably do better with the exception handling than I did.

Anyway you would have both processes using the same file name, and then they get to share paged memory together, with the OS using the file system for back-up if it doesn’t have any free memory pages. You can also use it to save data, I think you use the force method to make sure the OS has written every page to its backing file position.

---

<div class="post-metadata">

**Author:** ![seanc4s](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@seanc4s](https://discourse.processing.org/u/seanc4s)\
**Post date:** [January 27, 2026, 9:01am UTC](https://discourse.processing.org/t/ipc-shared-memory/47791/4 "2026-01-27T09:01:35Z")

</div>

At one stage I though I would need to handle massive memory for neural networks. That’s why I looked into memory mapped file.

In fact the neural networks I made have very small memory requirements.
