<div dir="ltr">Thanks Paul, that makes it quite clear.<div><br></div><div>/Björn</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-03-06 22:16 GMT+01:00 Paul Ramsey <span dir="ltr"><<a href="mailto:pramsey@cleverelephant.ca" target="_blank">pramsey@cleverelephant.ca</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's no better, do feel free to write directly into the pointer. Just make sure you aren't doing so w/i the context of an lwgeom that has been built directly on top of database-allocated memory. Namely, writing into this lwgeom is dangerous:<div><br></div><div>GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);</div><div>LWGEOM *lwg = lwgeom_from_gserialized(<wbr>gser);</div><div><br></div><div>Writing into this one (lwgc) is OK:</div><div><br></div><div><div>GSERIALIZED *gser = PG_GETARG_GSERIALIZED_P(0);</div><div>LWGEOM *lwg = lwgeom_from_gserialized(<wbr>gser);</div></div><div>LWGEOM *lwgc = lwgeom_clone_deep(lwg);</div><div><br></div><div>The first lwgeom is build with POINTARRAYs that point directly into the GSERIALIZED buffer. The second has POINTARRAYs that own their own buffers.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>P.</div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 6, 2017 at 12:35 PM, Björn Harrtell <span dir="ltr"><<a href="mailto:bjorn.harrtell@gmail.com" target="_blank">bjorn.harrtell@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="ltr">Ok I see, I didn't realize I was this close to the database storage/cache. <div><br></div><div>But then I fail to see how a memcpy straight into the pointer of a getPoint_internal can be any better? This is done all over the place.</div><span class="m_6546533340290988544HOEnZb"><font color="#888888"><div><br></div><div>/Björn</div></font></span></div><div class="m_6546533340290988544HOEnZb"><div class="m_6546533340290988544h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-03-06 21:28 GMT+01:00 Paul Ramsey <span dir="ltr"><<a href="mailto:pramsey@cleverelephant.ca" target="_blank">pramsey@cleverelephant.ca</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's not a struct alignment thing (anymore) but there is a danger in mutating the point array storage directly, because in the database context it's not clear who owns it, and we've had problems in the past w/ functions that directly write into the database storage. If you're going to be changing data, the safest thing is always to take a copy at the start.<div><br>P.</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_6546533340290988544m_8777424957369344052h5">On Mon, Mar 6, 2017 at 12:25 PM, Björn Harrtell <span dir="ltr"><<a href="mailto:bjorn.harrtell@gmail.com" target="_blank">bjorn.harrtell@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_6546533340290988544m_8777424957369344052h5"><div dir="ltr"><div>I want to mutate one axis of the points in a POINTARRAY in the most efficient way.</div><div><br></div><div>Something similar to ptarray_longitude_shift, see:</div><div><a href="https://github.com/postgis/postgis/blob/svn-trunk/liblwgeom/ptarray.c#L1393" target="_blank">https://github.com/postgis/pos<wbr>tgis/blob/svn-trunk/liblwgeom/<wbr>ptarray.c#L1393</a><br></div><div><br></div><div>I see memcpy being used there and other places and afaik it has something to do with fears of struct misalignment.</div><div><br></div><div>Does this mean I should most definitely not do this? :)</div><div><br></div><div><div>POINT2D *p = (POINT2D *) getPoint_internal(pa, 0);</div><div>p->y = extent - p->y;</div></div><div><br></div><div>Regards,</div><div>Björn<br></div></div>
<br></div></div>______________________________<wbr>_________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/postgis-devel</a><br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>