Re: sharing a complex sequence
- Posted by jimcbrown (admin) Jan 06, 2010
- 1170 views
Hi
This is a new-to-euphoria question, so please bear with me. I'd like to have a sequence in memory that several euphoria scripts could write to and read from. I 'could' do this by translating to C and adding some stuff, but is this possible from within the language?
TIA Hugh
The easiest way is to use sprint() to turn the sequence into a human readable string, and then use get() to turn to string back into an Euphoria object. (There are versions of sprint()/get() that transform into a machine-independent non-human readable compact format instead, if space is an issue.)
If for some reason, you need to pass the actual memory address of the sequence, using its internal Euphoria representation, around, you can do this as follows:
include std/dll.e --include dll.e -- use this instead if you are not use 4.0 constant CONVERT_TO_POINTER = define_c_func(open_dll(""), "labs", {E_SEQUENCE}, C_POINTER) -- for Windows, the open_dll("") call needs to be changed to the name of the Windows dll file, MSVCRT.DLL, that defines the labs() function. -- for FreeBSD, it needs to be changed to libc.so or libm.so function convert_to_pointer(sequence x) return c_func(CONVERT_TO_POINTER, {x}) end function
Euphoria doesn't include support for shared memory, however. There are libraries in the archives that add support for shared memory, but you would still need to deal with copying the sequence into and out of this shared memory.