Hi,

Am Do., 23. Juni 2022 um 19:42 Uhr schrieb Eliot Miranda <eliot.miranda@gmail.com>:


On Thu, Jun 23, 2022 at 10:28 AM Tony Garnock-Jones <tonyg@leastfixedpoint.com> wrote:
On 6/23/22 18:15, Eliot Miranda wrote:
> Can you say more about your use case?

I've been implementing the X11 protocol in pure Smalltalk and I want to
use a little bit of FFI to shmget/shmat and use that to get the pixels
over to the X server. At present XPutImage is working but flooding the
server with XPutImage seems to run into a rate limit from time to time
so it's not very usable. Best to switch to mmap/shm if I can.

Technical:

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?

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?

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.

https://docs.microsoft.com/en-us/windows/win32/memory/sharing-files-and-memory
shmget --> CreateFileMapping (or OpenFileMapping if you never want to create at the call site)
shmat --> MapViewOfFile (or MapViewOfFileEx)
shmdt --> UnmapViewOfFile
shmctl(IPC_RMID, ...) --> CloseHandle...

Of course there are different flags and security attributes for which the portability will vary.

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.

I cannot comment on the applicability for a Windows X Server.

Kind regards,
Jakob