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

Matthew Bromberg mattcbro at earthlink.net
Sat Jun 3 02:17:36 MEST 2006


Interesting, thanks I'll take a look at this.  I didn't see too much 
documentation on the garbage collector, or how one might control it.

The idea I had for passing function pointers would be to enable certain 
kinds of initialization or manipulation of data in an array from
some kind of configuration held in clean. An example from wireless comm. 
would be say a function that computes a channel matrix, based
on a whole bunch of configuration parameters, such as node positions 
velocities, terrain type, weather conditions etc.  call it hfunc(f, P) 
Once all the configuration information is processed however, the output 
can be thought of as a simple function of frequency or time or array 
index, etc.  So if the 'data structure' P has been computed  hfunc(f,P) 
is now just a function of f.

Thus the configuration information is essentially curried into the 
definition of the function.  Now I just pass that to the low level 
computation unit, who need not know anything about all that P stuff.  
All of a sudden, the supposed stateless functional language  is carrying 
a lot of state information.  Probably the only way this is going to 
happen is to export it via some dll as you suggest, which, if general 
enough, may be the best way to actually interface software in Clean to 
the outside world.



Marco Kesseler wrote:
>
> 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.
>
>
>>
>> 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