Question about D, garbage collection and fork()

Jerry Quinn jlquinn at optonline.net
Wed Mar 9 14:56:54 PST 2011


Where I work, we find it very useful to start a process, load data, then fork() to parallelize.  Our data is large, such that we'd run out of memory  trying to run a complete copy on each core.  Once the process is loaded, we don't need that much writable memory, so fork is appealing to share the loaded pages.  It's possible to use mmap for some of the data, but inconvenient for other data, even though it's read-only at runtime.

So here's my question:  In D, if I create a lot of data in the garbage-collected heap that will be read-only, then fork the process, will I get the benefit of the operating system's copy-on-write and only use a small amount of additional memory per process?

In case you're wondering why I wouldn't use threading, one argument is that if you have a bug and the process crashes, you only lose one process instead of N threads.  That's actually useful for robustness.

Thoughts?




More information about the Digitalmars-d mailing list