[FFI] moving large memory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[FFI] moving large memory

Nicolas Cellier-3
I want to transfer some memory between an ExternalAdress holding an array of
anything and Smalltalk memory (ByteArray for example).

I did figure well how to do it element by element, but didn't find anything
really efficient as a memcopy for example...

Does anyone have a clue, a package, a howto or something for me?
Thanks

Nicolas


Reply | Threaded
Open this post in threaded view
|

Re: [FFI] moving large memory

Alan Grimes-2
nicolas cellier wrote:
> I want to transfer some memory between an ExternalAdress holding an array of
> anything and Smalltalk memory (ByteArray for example).
>
> I did figure well how to do it element by element, but didn't find anything
> really efficient as a memcopy for example...
>
> Does anyone have a clue, a package, a howto or something for me?
> Thanks

Common practice is to use BitBlt from the graphics system. I don't like
that solution for obvious reasons but I'm sure you can find some example
code...

--
Don't let your schoolwork get in the way of your learning.

### NEW E-MAIL: [hidden email] ###

Reply | Threaded
Open this post in threaded view
|

Re: [FFI] moving large memory

Andreas.Raab
In reply to this post by Nicolas Cellier-3
Hi Nicolas -

Currently, there isn't any such method. The best thing you can do is to
call memcpy directly from your libc or so (assuming you're on a system
that gives you access to it - on windows you might have to use
MoveMemory or somesuch).

Cheers,
   - Andreas

nicolas cellier wrote:

> I want to transfer some memory between an ExternalAdress holding an array of
> anything and Smalltalk memory (ByteArray for example).
>
> I did figure well how to do it element by element, but didn't find anything
> really efficient as a memcopy for example...
>
> Does anyone have a clue, a package, a howto or something for me?
> Thanks
>
> Nicolas
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [FFI] moving large memory

Nicolas Cellier-3
In reply to this post by Alan Grimes-2

Le Mercredi 17 Mai 2006 02:21, Alan Grimes a écrit :
> Common practice is to use BitBlt from the graphics system. I don't like
> that solution for obvious reasons but I'm sure you can find some example
> code...

Alan, thanks,
it seems convenient to move memory from Smalltalk to Smalltalk,
but i did not see any example using an ExternalAddress.
Since ExternalAddress are ByteArray with four bytes containing the address,
i'am afraid it won't be interpreted as a pointer, but an array of 32bits...
Or maybe i am wrong?

Le Mercredi 17 Mai 2006 05:46, Andreas Raab a écrit :
> Hi Nicolas -
>
> Currently, there isn't any such method. The best thing you can do is to
> call memcpy directly from your libc or so (assuming you're on a system
> that gives you access to it - on windows you might have to use
> MoveMemory or somesuch).
>
> Cheers,
>    - Andreas

Andreas, thanks
but then how do i gain pointer access to data through smalltalk oop?
Is there another way but writing a plugin?
If i must write a plugin, i suggest this kind of basic service being included
in future FFI releases.

Nicolas



Reply | Threaded
Open this post in threaded view
|

Re: [FFI] moving large memory

johnmci

On 17-May-06, at 4:47 AM, nicolas cellier wrote:

>
> Alan, thanks,
> it seems convenient to move memory from Smalltalk to Smalltalk,
> but i did not see any example using an ExternalAddress.
> Since ExternalAddress are ByteArray with four bytes containing the  
> address,
> i'am afraid it won't be interpreted as a pointer, but an array of  
> 32bits...
> Or maybe i am wrong?

In Sophie before using a Quicktime call to write bits into an  
external display surface we moved data from a a quicktime GWorld into  
a instance of Form
using  the original mac os blockmovedata call which btw resolves to  
bcopy.

fields
        "MacPixMapHandle defineFields"
        ^#((nil 'long'))


updateOffscreenForm
        | src dataSize |
        src := self pixMapHandle getPixBaseAddr. "This returns a a memory  
address"

        dataSize := (self offscreenForm width * 4) * self offscreenForm height.
        SophieQuickTimeInterface apiBlockMoveData: src dest: (self  
offscreenForm bits) size: dataSize

"self offscreenForm bits  points to the ByteArray of the Form"


apiBlockMoveData: srcPtr dest:destPtr size:size
        <cdecl: void 'BlockMoveData' (long long* long )  
module:'Carbon.framework'>
        ^ self externalCallFailed



"void BlockMoveData (
    const void * srcPtr,
    void * destPtr,
    Size byteCount
); "



--
========================================================================
===
John M. McIntosh <[hidden email]> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
========================================================================
===


Reply | Threaded
Open this post in threaded view
|

Re: [FFI] moving large memory

Nicolas Cellier-3

Thanks John,

I hadn't understood that the ByteArray can be simply passed as char* and
WordArray as long* in FFI, so your tip helped me a lot.

Le Mercredi 17 Mai 2006 13:47, nicolas cellier a écrit :
> Andreas, thanks
> but then how do i gain pointer access to data through smalltalk oop?
> Is there another way but writing a plugin?
>
> Nicolas

Yes, i understand at last FFI do that for us.
Apologies to Andreas for my being a little slow-brained, his solution was
good.

Nicolas


Le Mercredi 17 Mai 2006 18:55, John M McIntosh a écrit :

> On 17-May-06, at 4:47 AM, nicolas cellier wrote:
> > Alan, thanks,
> > it seems convenient to move memory from Smalltalk to Smalltalk,
> > but i did not see any example using an ExternalAddress.
> > Since ExternalAddress are ByteArray with four bytes containing the
> > address,
> > i'am afraid it won't be interpreted as a pointer, but an array of
> > 32bits...
> > Or maybe i am wrong?
>
> In Sophie before using a Quicktime call to write bits into an
> external display surface we moved data from a a quicktime GWorld into
> a instance of Form
> using  the original mac os blockmovedata call which btw resolves to
> bcopy.
>
> fields
>  "MacPixMapHandle defineFields"
>  ^#((nil 'long'))
>
>
> updateOffscreenForm
>
>  | src dataSize |
>
>  src := self pixMapHandle getPixBaseAddr. "This returns a a memory
> address"
>
>  dataSize := (self offscreenForm width * 4) * self offscreenForm height.
>  SophieQuickTimeInterface apiBlockMoveData: src dest: (self
> offscreenForm bits) size: dataSize
>
> "self offscreenForm bits  points to the ByteArray of the Form"
>
>
> apiBlockMoveData: srcPtr dest:destPtr size:size
>  <cdecl: void 'BlockMoveData' (long long* long )
> module:'Carbon.framework'>
>  ^ self externalCallFailed
>
>
>
> "void BlockMoveData (
>     const void * srcPtr,
>     void * destPtr,
>     Size byteCount
> ); "
>
>
>
> --
> ========================================================================
> ===
> John M. McIntosh <[hidden email]> 1-800-477-2659
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ========================================================================
> ===