@@ -4158,37 +4158,47 @@ requests and the memory waste.
41584158
41594159[endsect]
41604160
4161- [section:copy_on_write_read_only Opening managed shared memory and mapped files with Copy On Write or Read Only modes]
4161+ [section:copy_on_write_read_only Opening managed shared memory and mapped files in [' Copy On Write] or [' Read Only] modes]
41624162
4163- When mapping a memory segment based on shared memory or files, there is an option to
4164- open them using [*open_copy_on_write] option. This option is similar to `open_only` but
4165- every change the programmer does with this managed segment is kept private to this process
4166- and is not translated to the underlying device (shared memory or file).
4163+ [section:open_copy_on_write_mode ['open_copy_on_write] mode]
41674164
4168- The underlying shared memory or file is opened as read-only so several processes can
4169- share an initial managed segment and make private changes to it. If many processes
4170- open a managed segment in copy on write mode and not modified pages from the managed
4171- segment will be shared between all those processes, with considerable memory savings .
4165+ The programmer can open a managed shared memory or mapped file using the `open_copy_on_write`
4166+ option. This option is similar to `open_only` but
4167+ every change performed on this managed segment is kept private to the process
4168+ and those changes are not translated to the underlying device (shared memory or file) .
41724169
4173- Opening managed shared memory and mapped files with [*open_read_only] maps the
4170+ This copy-on-write approach can reduce memory consumption:
4171+
4172+ * Sharing of identical pages: When multiple processes use `open_copy_on_write`,
4173+ the operating system initially makes them share the same underlying physical memory pages.
4174+ No actual copying of the data occurs at the time of opening.
4175+
4176+ * Copy only on modification: A private copy of portion of the managed segment is created in process-private memory
4177+ only when one of the processes attempts to write that portion. Processes that only read most of the data continue to share the
4178+ original portions (memory pages). This can lead to substantial memory savings, especially when dealing with large datasets or
4179+ when many processes need to access the same data with only a few modifying it.
4180+
4181+ [endsect]
4182+
4183+ [section:open_read_only_mode ['open_read_only] mode]
4184+
4185+ Opening a managed shared memory or managed mapped file with `open_read_only` maps the
41744186underlying device in memory with [*read-only] attributes. This means that any attempt
4175- to write that memory, either creating objects or locking any mutex might result in an
4176- page-fault error (and thus, program termination) from the OS. Read-only mode opens
4177- the underlying device (shared memory, file...) in read-only mode and
4178- can result in considerable memory savings if several processes just want to process
4179- a managed memory segment without modifying it. Read-only mode operations are limited:
4187+ to write to that memory (including locking any mutex) might result in a
4188+ page-fault error (and thus, program termination) from the OS.
41804189
4181- * Read-only mode must be used only from managed classes. If the programmer obtains
4182- the segment manager and tries to use it directly it might result in an access violation.
4183- The reason for this is that the segment manager is placed in the underlying device
4184- and does not nothing about the mode it's been mapped in memory.
4190+ Due to this, managed shared memory or managed mapped file operations are quite limited on this mode:
41854191
4186- * Only const member functions from managed segments should be used.
4192+ * Only const member functions from managed shared memory/mapped file should be used.
4193+ If the programmer obtains the segment manager and tries to use any available operation on that object,
4194+ it might result in an access violation.
41874195
41884196* Additionally, the `find<>` member function avoids using internal locks and can be
41894197 used to look for named and unique objects.
41904198
4191- Here is an example that shows the use of these two open modes:
4199+ [endsect]
4200+
4201+ Here is an example that shows the use of these two modes:
41924202
41934203[import ../example/doc_managed_copy_on_write.cpp]
41944204[doc_managed_copy_on_write]
0 commit comments