Memory Sharing Library
Version: 3.2
Written by: Jason Mirwald and Mario Steele
Emails: mirwalds@prodigy.net
systemcrashalpha@yahoo.com
What is memshare.ew ?
This library is designed to allow two or more win32 applications to share a
block of contiguous memory. The memory block is identified by a unique
null-terminated string (not necessarily a character string) which is maintained
internally by windows.
The shared memory address used/returned by the routines is a standard memory
address such as an address that is returned by allocate() or any of it's
variations. The block of shared memory can be referenced using any of the
Euphoria reading/writing memory routines.
Each application that requests a handle to shared memory must close it's handle
before the memory will be returned to the system. This operates a little
differently from standard allocated memory, in that the application that
originally allocated the memory can close it's handle, and the memory will
continue to exist for other applications to use as long as at least one other
application has a handle to it.
The routines contained in this library will return one of the following values if an error occurs while trying to create or open shared memory. The values are all negative integers, and can be used to help identify what specific error occurred during the calls.
SM_CREATE_EXIST = Shared memory already exists
SM_CREATE_FAIL = Failed to create Shared Memory
SM_OPEN_FAIL = Failed to obtain a valid Memory
Address
SM_MEM_FAIL = Failed to allocate Standard
Memory for the operation
sm_create()
Syntax:
addr = sm_create( sequence name, atom nbytes )
Description:
This routine attempts to allocate a contiguous block of shared memory, nbytes in length, that will be uniquely identified by name. If another block of memory exists, that is already identified by name, the memory will not be allocated.
NOTE:
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.
Return:
This function returns the address of the block of memory identified by name if it does not already exist. If name already exists as shared memory or cannot be allocated, sm_create() will return one of the predefined error values.
Syntax:
a = sm_open( sequence name )
Description:
This routine attempts to retrieve the address of a block of shared memory, identified by name, that has already been allocated for use by another application.
NOTE:
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.
Return:
This function returns the address of the block of memory identified by name if it already exists. If name does not exist as shared memory or cannot be allocated, sm_open() will return one of the predefined error values.
Syntax:
addr = sm_alloc_lpsz( sequence name, sequence s )
Description:
This routine attempts to allocate a contiguous block of shared memory long enough to store the sequence s, that will be identified by the sequence name. If another block of memory exists, that is already identified by name, the memory will not be allocated.
NOTE:
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.
Return:
This function returns the address of the block of memory identified by name if it does not already exist. If name already exists as shared memory or cannot be allocated, sm_alloc_lpsz() will return one of the predefined error values.
Syntax:
sm_close( object id )
Description:
This routine releases an applications handle to a block of shared memory. Once an application calls sm_close(), that memory is no longer valid memory to that application. The object id can be either the address returned by sm_create() or sm_open(), or the actual string-id used to identify the memory.
NOTE:
When an application closes shared memory, it does not mean that the memory is no longer valid to other applications.
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.
Return:
This procedure does not return a value.