<div dir="ltr"><div>Hi,</div><div><br></div><div>Am Do., 23. Juni 2022 um 19:42 Uhr schrieb Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>>:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 23, 2022 at 10:28 AM Tony Garnock-Jones <<a href="mailto:tonyg@leastfixedpoint.com" target="_blank">tonyg@leastfixedpoint.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 6/23/22 18:15, Eliot Miranda wrote:<br>
> Can you say more about your use case?<br>
<br>
I've been implementing the X11 protocol in pure Smalltalk and I want to <br>
use a little bit of FFI to shmget/shmat and use that to get the pixels <br>
over to the X server. At present XPutImage is working but flooding the <br>
server with XPutImage seems to run into a rate limit from time to time <br>
so it's not very usable. Best to switch to mmap/shm if I can.<br></blockquote><div><br></div><div><div style="font-size:small">Technical:</div><br></div><div style="font-size:small">So in this use including the header in the first page would be ok?  Would the mapping be read-only from the perspective of the X server?  Do you need shmget to be run via the FFI or would it be OK to invoke it implicitly as part of a mapping allocation primitive?  Would it be better to create the mapping via the FFI and provide the mapping to the allocation primitive? How should the mapping be taken down?</div><div style="font-size:small"><br></div><div style="font-size:small"><div>Windows folks, how portable is this idea to other OS's, especially windows?  (I'm guessing this is a standard facility on most leading OS's).  So would it be worth evolving towards a cross-platform abstraction?</div></div></div></div></blockquote><div><br></div><div>If the question is "does Windows support shared memory in a way that is similar to POSIX shmget/shmat", I can definitely say yes. At work we have software that runs on both Windows and AIX, uses shared memory for inter-process communication under the hood, and has the API calls for both platforms abstracted uniformly for both platforms.</div><div><br></div><div><a href="https://docs.microsoft.com/en-us/windows/win32/memory/sharing-files-and-memory">https://docs.microsoft.com/en-us/windows/win32/memory/sharing-files-and-memory</a></div><div>shmget --> CreateFileMapping (or OpenFileMapping if you never want to create at the call site)</div><div>shmat --> MapViewOfFile (or MapViewOfFileEx)</div><div>shmdt --> UnmapViewOfFile</div><div>shmctl(IPC_RMID, ...) --> CloseHandle...</div><div><br></div><div>Of course there are different flags and security attributes for which the portability will vary.</div><div><br></div><div>Moreover, if you want to wrap OS shared memory objects in Squeak, also consider doing the same for OS semaphores or other synchronization primitives. If two processes want to write, or you don't want to read inconsistent data in the absence of atomic writes, you will want some kind of inter-process synchronization.</div><div><br></div><div>I cannot comment on the applicability for a Windows X Server.</div><div><br></div><div>Kind regards,<br>Jakob</div></div></div>