On 23 September 2013 21:40, Igor Stasenko <siguc...@gmail.com> wrote:

>
>
>
> On 23 September 2013 16:23, Camillo Bruni <camillobr...@gmail.com> wrote:
>
>> Hi Jan,
>>
>> I think I will add the ByteArray accessor to NBExternalAddress today
>> or tomorrow since I need it as well for another project.
>>
>> hmm, reading from memory into bytearray can be done with memory copy:
>
> inputs: address , offset , size to read
>
> newAddress := NBExternalAddress value: address value + offset.
> buffer := ByteArray new: size.
> NativeBoost memCopy: newAddress to: buffer size: size.
>
> same way, writing, just swap the source and destination:
>
> newAddress := NBExternalAddress value: address value + offset.
> buffer "is given from somewhere".
> NativeBoost memCopy: buffer  to: newAddress size: size.
>
> but as Jan noted, you cannot tell to write starting at specified offset
> from/to bytearray, e.g.:
>
> copy from: address to: buffer + someOffset
> neither:
> copy from: buffer + someOffset to: someAddress
>
> this  where we need to introduce special 'field address' type, so you can
> construct it like this:
>
> offsetAddress := buffer nbAddressAt: offset.
>
> so then you can use it to pass to any function, which expects address,
> like memory copy
> or any foreign function.
>
> Since objects are moving in memory, we cannot calculate address of field
> before hand:
>
> address := NBExternalAddress value:  someObject address + offset.
>
> because if GC will happen, after computing such address and its actual use,
> you will read/write to wrong location.
>

** after computing and *before* actual use **


> Thus we should keep oop + offset up to the point of passing it to external
> function, under
> controllable conditions, that guarantee there's no GC is possible.
>
>
> Things would be much simpler if we could have pinning, isnt? :)


> --
> Best regards,
> Igor Stasenko.
>


-- 
Best regards,
Igor Stasenko.

Reply via email to