I should correct this -- after a private discussion with John Ferrence
where he pointed out an error in my thinking.

This works:

s=: 'Hello world'
write=: {{p [ y memw p,0,(>: # y),2 [ p=. mema >: # y=.y,a.}}
read =: {{res [ memf y [ res=. memr y,0,_1,2}}

The issue where a version of this implementation without y=.y,a. would
fail with garbage reads was probably was introduced in J901 beta-e

https://wiki.jsoftware.com/wiki/System/ReleaseNotes/J901 says: "New
feature: virtual extended nouns. If a noun that is not referred to
more than once is extended by appending items to the end, the extended
value and the original value share the same data without copying"

In previous implementations of J, character nouns had a trailing ascii
null appended during allocation, immediately following the represented
characters, and the implementation relied on this to simplify
interaction with the C api, and I expect that that "0 is appended"
line in https://code.jsoftware.com/wiki/Guides/DLLs/Memory_Management
was a reference to this practice.

FYI,

-- 
Raul

On Fri, Feb 25, 2022 at 3:12 PM Raul Miller <[email protected]> wrote:
>
> I am trying to understand what you mean here.
>
> Your 'read' verb does not read from memory. Instead, it writes a zero
> to an offset in some freshly allocated memory and returns the address
> of that allocation.
>
> Similarly, your 'write' verb does not write to memory. Instead, it
> reads characters from the previously allocated memory, up to the point
> where it finds a zero (and fortunately, you had ensured that there
> would be one when you invoked 'read').
>
> Anyways, basically it looks like you've built a small system to read
> some arbitrary bytes from memory and then are using them in some
> larger algorithm.
>
> But I am not sure why you would expect an operation which reads
> arbitrary memory to be deterministic.
>
> Have I overlooked something important?
>
> Thanks,
>
> --
> Raul
>
> On Fri, Feb 25, 2022 at 3:01 PM John Ference <[email protected]> wrote:
> >
> > Hello,
> > Is this construction consistent with the design specs of the memory
> > management functions?
> >
> > s =. 'Hello world'
> >
> > read =. {{p [ y memw p,0,(>: # y),2 [ p =. mema >: # y}}
> >
> > write =. {{res [ memf y [ res =. memr y,0,_1,2}}
> >
> >
> > NB. test:
> >
> > <./ (,. write@read&.> <\ s) = (,. <\ s)
> >
> > Results are non-deterministic, but the results at the test at the end
> > typically return 0.
> >
> > Visual inspection of the result suggests the capability to auto-append and
> > then auto-find an end-of-string indicator may not be working.
> >
> > specs: https://code.jsoftware.com/wiki/Guides/DLLs/Memory_Management
> >
> > Regards,
> > John
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to