1. sharing a complex sequence
- Posted by hughbarnard Jan 06, 2010
- 1067 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
2. Re: sharing a complex sequence
- Posted by useless Jan 06, 2010
- 1119 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
Once upon a time, "shared memory" would work. I have not tried it in v4 yet.
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=shared+memory
HTH,
useless
3. Re: sharing a complex sequence
- Posted by jimcbrown (admin) Jan 06, 2010
- 1169 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.
4. Re: sharing a complex sequence
- Posted by hughbarnard Jan 06, 2010
- 1130 views
Hi everyone
Thanks for the very quick replies..I wanted something like shared memory, so I'll give that a spin soon. Meanwhile, I'll emulate with a big sprawling thing in /tmp. If I get anything useful going, I'll post..
Thanks again Hugh
5. Re: sharing a complex sequence
- Posted by jimcbrown (admin) Jan 06, 2010
- 1128 views
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
Whoops, I made a mistake. labs() might corrupt the pointer. Instead, we can do this:
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(""), "ldiv", {E_SEQUENCE, C_LONG}, 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 ldiv() 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, 1}) end function
ldiv() actually returns two values, in a struct, but we only deal with the first half here as we can safely ignore the second half.