[clean-list] Sub-arrays How do I manipulate an array pointer?

Marco Kesseler m.kesseler at xs4all.nl
Sat Jun 3 01:02:11 MEST 2006


WAARSCHUWING: Dit bericht is door de mailserver software aangepast!
De volgende paragraaf geeft indicaties van gedane aanpassingen.
-----------------
WARNING: This e-mail has been altered by the mailserver software!
Following this paragraph are indications of the actual changes made.
-----------------
      - Postmaster <postmaster at science.ru.nl>


Een bijlage genaamd windows.zip werd verwijderd uit dit document omdat dit
een veiligheids risico vormde. Als deze bijlage toch gewenst is, neem dan contact
op met de afzender en gebruik een andere manier om deze bijlage te verkrijgen.
-----------------
An attachment named windows.zip was removed from this document as it
constituted a security hazard. If you require this document, please contact
the sender and arrange an alternate means of receiving it.
-----------------
- Dangerous zip archive contains: Work/msg-28905-30.zip
-----------------

-------------- next part --------------

On Jun 2, 2006, at 10:54 PM, Matthew Bromberg wrote:

>
> It would be nice though to use Clean's array comprehensions to  
> initialize or alter values held in a matrix.
> Are there any nice hacks for processing array data held in C but  
> not managed by Clean? Can the
> garbage collector be told to leave an array alone?  I think it's  
> possible already to return data from a
> C array, but it's copied as soon as it gets into Clean I believe.  
> (At least it works that way for strings I'm told.)

I have attached a small zip file with some experimental code for my  
"funlib" project. In "Files.icl" there is a "newStringFile" function  
that creates a memory mapped writable file for the characters in a  
string. The header is left out of the file, using a virtual memory  
trick. It avoids copying the string by passing the pointer to it as  
an Int to Clean. Then, some abc instructions are used to push this  
integer as a pointer on the a-stack and "cast" it to a String.

Provided that you keep the string unique, you can write characters  
into this string in Clean itself, and these will "magically" end up  
in the file. As long as the string is located outside the Clean heap,  
the garbage collector will not touch it. For large strings this  
improves garbage collection times considerably, because Clean does  
not need to copy it around. Keeping the string unique is essential  
though, as otherwise you will end up with a copy of the string inside  
the heap...

I believe that similar things can be done for unboxed arrays, but  
only if you use the marking garbage collector.

-------------- next part --------------

>
> Equivalently if I could have a C enabled function pointer from  
> Clean that could be used to process raw data,
> that would be pretty useful.  In fact even if I could get very  
> simple functions  like
>
> Int Int -> Int or
> Double -> Double
>
> from Clean into C it could be quite useful.  These functions would  
> probably be curried with lots of configuration data.
>

I am not 100% certain that I follow you here. It is possible to call  
clean functions from C, if you let the clean compiler generate a DLL,  
For a bit of info, see: http://www.xs4all.nl/~keslr/functional/clean/ 
howto/cleandll.html

This however, is not the same as passing Clean functions to C and  
calling them from there. I have considered trying this out, but never  
did it, so sorry, can't help you here.

regards,
Marco
>



More information about the clean-list mailing list