<div dir="auto"><div>Eliot,<div dir="auto"><br></div><div dir="auto">That sounds very straightforward and logical.  I had only taken a quick glance in a recent image and didn't notice anything obvious in FFI so I thought I'd just ask before going further.</div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">Thanks for the tip re: making sure to keep a reference in the image to avoid gc as I'm sure that would have bitten me at some point since my plan is to try creating some reusable buffers see if I can speed up some things re: text and image processing. (i.e. I might not have thought to hang onto it once it had been passed to FFI which I'm sure would not have been fun to track down)</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">Also just FYI, I'm also looking forward to your threaded FFI work as I'm hoping to be able to create a persistent rendering thread for OpenGL (this could be a performance gain of up to 80-90% for heavy rendering code) which should also benefit from pinning.</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">Thanks,</span></div><div dir="auto"><span style="font-family:sans-serif">Phil</span></div><br><div class="gmail_extra"><br><div class="gmail_quote">On Aug 24, 2017 6:06 PM, "Eliot Miranda" <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Phil,<div class="gmail_extra"><br><div class="gmail_quote"><div class="quoted-text">On Thu, Aug 24, 2017 at 1:36 PM, Phil B <span dir="ltr"><<a href="mailto:pbpublist@gmail.com" target="_blank">pbpublist@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I remember reading a while back that Spur added memory pinning and was curious if any Squeak packages has made use of it yet? (Looking for an example or two to get me started)</div></blockquote><div><br></div></div><div>The protocol i in Object, with the selectors pin, unpin and isPinned.  You can send any of these to any non-immediate object.  It is your responsibility to avoid calling unpin until external code no longer holds references to any pinned object.  It is your responsibility to arrange that the objects are still accessible within the system so that they are not GCed while external code holds onto them.  Pinning is orthogonal to GC.  It prevents the GC from moving objects, but does not prevent them from being GCed if no references to them exist in the Smalltalk system.  Note that also pinning may cause an object to move from newSpace to oldSpace, as objects are only pinball in oldSpace.  Pinning a new object causes it to become a copy of the object in oldSpace, so do not pass an object to external code and then pin it; it may move.</div><div><br></div><div> So the idea is</div><div>- create some objects you want to share with external code and pin them</div><div>- pass them to that external code through the FFI</div><div>- allow that external code to run (e.g spawn a thread in the external code, or make subsequent call though the FFI exercise the code)</div></div>- shut down the external code</div><div class="gmail_extra">- unpin your objects, or merely allow them to be GCed.<br><br>Alternatively external code can pin the objects it is given, providing it updates their location afterwards.  See pinObject:.</div><div class="gmail_extra"><br clear="all"><div>Note that you should use the interpreterProxy accessors firstIndexableField: and firstFixedField: to find out the start of the body of an object (pinned or otherwise).  byteSizeOf:, instanceSizeOf:, slotSizeOf: and stSizeOf: can all be used to find out various sizes.  See platforms/Cross/vm/<wbr>sqVirtualMachine.h, which also provides pinObject: and unpinObject:.</div><div><br></div><div>Clearly some work is needed to add documentation in the right places.  LMK where you looked, where you would expect to find such information, etc.</div><font color="#888888">-- <br><div class="m_-8146952467565112426gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</font></div></div>
<br><br>
<br></blockquote></div><br></div></div></div>