On Thursday, January 21, 2016 at 2:26:50 PM UTC-5, antoine wrote:
> To make it clear here is what i have in mind:
> 
> #lang racket
> 
> ;; dummy function, just remplace by A
> (define (do-stuff shared-data data-length)
>   (values
>    (make-bytes data-length 65)
>    data-length))
> 
> (define p
>   (place ch
>          (define shared-data (place-channel-get ch))
>          (let loop ()
>            (define data-length (place-channel-get ch))
>            (define-values (new-data new-data-length) (do-stuff shared-data 
> data-length))
>            (bytes-copy!       shared-data 0 new-data 0 new-data-length)
>            (place-channel-put ch new-data-length)
>            (loop))))
> 
> (module+ main
>   (define shared-data (make-shared-bytes 10 66))
>   (place-channel-put p shared-data)
>   (place-channel-put p 5)
>   (place-channel-get p) ;; 5
>   (printf "~a\n" shared-data)  ;; AAAAABBBBB
>   (place-channel-put p 7)
>   (place-channel-get p) ;; 7
>   (printf "~a\n" shared-data)) ;; AAAAAAABBB
> 
> > But you would still need to copy the mutable byte string (returned by 
> > various byte string functions) to the shared byte string you create with 
> > make-shared-bytes, right? So, a byte string would still be copied.
> 
> Yes
> 
> > As someone suggested earlier, I could use read-bytes! and read directly 
> > into a byte string created by make-shared-bytes. Then I *think* the cost to 
> > "send" it to the worker place is minimal (maybe just sending a pointer). 
> > That would require some buffer bookkeeping to split lines, etc., but the 
> > workers would still need to copy their resulting byte strings to the output 
> > place.
> 
> Yes
> 
> > Maybe I'm being overprotective, but my hunch is that I need the output 
> > place to serialize access to the output file vs. having the worker places 
> > write directly to it, but if Racket serializes access to the output port, 
> > maybe I can skip that.
> 
> According to the doc it seem you can't pass output-file-port.

I think I get what you're saying, but the trouble is to do this requires 
changing just about everything in the code i.e. manipulating indices into a 
shared buffer vs. having functions returning byte strings. It's much closer to 
what I did in the C program - definitely faster, but more manual bookkeeping 
for the programmer.

So, instead of programming in a more functional way - pass in a byte string, do 
some work and return another byte string. You would pass in a mutable byte 
string with a begin and end indices, do some work and return the updated 
indices, etc.

You can pass file ports across place channels - I send the output port to the 
output place, and it works fine. What I don't know is whether Racket would 
serialize N places that are writing to one port.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to