rtapi_shmem(3rtapi)
π rtapi_shmem π
okay bestie, gather round, because this is rtapi_shmem(3rtapi) β the RTAPI page all about shared memory blocks, and it's genuinely so iconic. Three little functions, one big vibe: let different modules peek at the same chunk of memory. no cap. π«Ά
β¨ NAME β¨
rtapi_shmem β functions for managing shared memory blocks π§ β¨
πΈ SYNTAX πΈ
int rtapi_shmem_new(int key, int module_id, unsigned long int size)
int rtapi_shmem_delete(int shmem_id, int module_id)
int rtapi_shmem_getptr(int shmem_id, void ** ptr)
that's the whole lineup, bestie. three functions, all returning int, all living their main character era. π
π ARGUMENTS π
keyβ this is the thing that identifies the memory block. it must be nonzero (like, non-negotiable, zero is not it π ). and listen: every module that wants to use the same memory has to use the same key. same key = same block, periodt.module_idβ the module identifier you got back from an earlier call tortapi_init. yep, you gotta be initiated first, iykyk. π¦sizeβ how big you want your shared memory block, in bytes. πptrβ the pointer to the shared memory block. heads up though: the block may be mapped at a different address for different modules. so don't go assuming everyone sees it at the same spot, because they fr fr might not. π
π DESCRIPTION π
rtapi_shmem_new π
rtapi_shmem_new allocates a block of shared memory. key identifies the memory block, and it must be non-zero. all modules wishing to access the same memory must use the same key. module_id is the ID of the module making the call (see rtapi_init).
the block will be at least size bytes, and may be rounded up. and lowkey this next bit matters: allocating many small blocks may be very wasteful. so don't be out here making a million tiny blocks, bestie, it's giving chaos. π
when a particular block is allocated for the first time, the contents are zeroed. subsequent allocations of the same block by other modules or processes will not touch the contents of the block. and that's actually a feature, not a bug β applications can use those bytes to see if they need to initialize the block, or if another module already did it for them. teamwork! π€β¨
on success, it returns a positive integer ID, which is used for all subsequent calls dealing with the block. on failure it returns a negative error code. so if you get a negative number back, that's your sign, bestie. π©
rtapi_shmem_delete ποΈ
rtapi_shmem_delete frees the shared memory block associated with shmem_id. module_id is the ID of the calling module. returns a status code. bye bye block π
rtapi_shmem_getptr π
rtapi_shmem_getptr sets *ptr to point to the shared memory block associated with shmem_id. that's it, that's the whole job. simple, clean, slay. π
π₯ REALTIME CONSIDERATIONS π₯
okay this part is the vibe check of the whole page, so pay attention:
rtapi_shmem_getptrmay be called from non-realtime code, init/cleanup code, or realtime tasks. flexible queen. πrtapi_shmem_newandrtapi_shmem_detemay not be called from realtime tasks. π«β±οΈ
not me pointing out that the page literally spells it rtapi_shmem_dete right there π β that's exactly how it's written, so that's exactly how i'm writing it. take it up with the source, bestie.
β RETURN VALUE β
so this section exists, but the page doesn't actually say anything under it β it just goes straight to the footer. π the return value tea is all up in the DESCRIPTION section: rtapi_shmem_new gives you a positive integer ID on success and a negative error code on failure, and rtapi_shmem_delete returns a status code. that's the whole story, fr fr.
and that's the page, bestie!! πβ¨ this was rtapi_shmem(3rtapi) from the LinuxCNC Documentation, dated 2006-10-12 β vintage but still eating, no crumbs left. ππ¦ go forth and share that memory responsibly. mwah. π
πΈ
π¦ where this page comes from
- debian trixie: linuxcnc-uspace-dev 1:2.9.4-2+deb13u1 Β· GFDL-1.1-or-later
- ubuntu questing: linuxcnc-uspace-dev 1:2.9.4-2ubuntu2
- ubuntu resolute: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- ubuntu stonking: linuxcnc-uspace-dev 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms