Definition: |
include builtins\ipc.e atom pSharedMem = sm_create(string name, integer nbytes) |
Description: |
Allocates a contiguous block of shared memory, nbytes in length, that will be uniquely identified by name.
Returns: the address of the newly created block of memory. If a block of memory that is identified by name already exists, or the memory cannot be allocated, then sm_create() returns one of the predefined error values. |
Comments: |
Before attempting to create a new block of memory, sm_open() can be called to find out if the name already exists.
Each application must call sm_close() to close it’s handle to the shared memory. A block of shared memory will continue to exist until all handles to it have been closed. |
Example: |
include builtins\ipc.e include builtins\serialize.e sequence s = {"Pete",{-1,0,1},PI,-PI}, enc_s = serialize(s) integer len = length(enc_s) atom pMem = sm_create("test",len+4) poke4(pMem,len) poke(pMem+4,enc_s) --atom pMem = sm_open("test") -- (if a separate process) ?deserialize(peek({pMem+4,peek4s(pMem)})) -- shows {"Pete",{-1,0,1},3.141592654,-3.141592654} sm_close(pMem) Obviously, in a client/server scenario, the sm_close() corresponding to an sm_create() in the server should not occur before the sm_open() in the client, but otherwise, if there are two, it does not matter which sm_close() happens first. |
See Also: | sm_open sm_close serialize deserialize |