[postgis-devel] PgSQL Memory Stuff
Nicklas Avén
nicklas.aven at jordogskog.no
Sun Dec 12 05:19:28 PST 2010
I have been looking through the measure functions according to the
example below, (in 2D I think you have fixed most of it Paul, but not in
3d).
I have two questions
question 1) In LWGEOM_mindistance2d for instance there is this
PROFSTART(PROF_QRUN)
and
PROFSTOP(PROF_QRUN);
PROFREPORT("dist",geom1, geom2, NULL);
I have just left it there earlier because I have had no idea what it is
for.
Can I just remove it? I see very few other functions have this profile
thing. Or is it of any use?
question 2)
In the example below there is this null-return if the result is empty:
if (lwgeom_is_empty(theline))
PG_RETURN_NULL();
Should we care about freeing stuff in this case too. I guess it wouldn't
be anything wrong in doing it at least?
like:
if (lwgeom_is_empty(theline))
{
lwgeom_free(theline);
lwgeom_free(lwgeom1);
lwgeom_free(lwgeom2);
PG_FREE_IF_COPY(geom1, 0);
PG_FREE_IF_COPY(geom2, 1);
PG_RETURN_NULL();
}
As I understand it there should not be any problem freeing "theline"
with lwgeom_free even if it is empty in any way.
Thanks
Nicklas
On Tue, 2010-12-07 at 16:27 -0800, Paul Ramsey wrote:
> Nik,
> Here's an annotated version of one of your functions, none of this
> stuff is critical, since pgsql just cleans right up behind you, but in
> case you want to do it "right"...
>
>
> PG_FUNCTION_INFO_V1(LWGEOM_shortestline2d);
> Datum LWGEOM_shortestline2d(PG_FUNCTION_ARGS)
> {
> PG_LWGEOM *result;
> /* Detoast the actual PgSQL varlena structures, in our case PG_LWGEOM
> (soon to be GSERIALIZED) */
> PG_LWGEOM *geom1 = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
> PG_LWGEOM *geom2 = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
> /* Build LWGEOM from the varlena (soon to be with lwgeom_from_gserialized) */
> LWGEOM *lwgeom1 = pglwgeom_deserialize(geom1);
> LWGEOM *lwgeom2 = pglwgeom_deserialize(geom2);
> LWGEOM *theline;
>
>
> if (lwgeom1->srid != lwgeom2->srid)
> {
> elog(ERROR,"Operation on two GEOMETRIES with different SRIDs\n");
> PG_RETURN_NULL();
> }
>
> theline = lw_dist2d_distanceline(lwgeom1, lwgeom2, lwgeom1->srid, DIST_MIN);
> if (lwgeom_is_empty(theline))
> PG_RETURN_NULL();
>
> /* Serialize the result back down from LWGEOM, but don't return right away */
> result = pglwgeom_serialize(theline);
> /* First free the LWGEOMs you used */
> lwgeom_free(lwgeom1);
> lwgeom_free(lwgeom2);
>
> /* Then call free_if_copy on the *varlena* structures you originally
> get as arguments */
> PG_FREE_IF_COPY(geom1, 0);
> PG_FREE_IF_COPY(geom2, 1);
>
> /* And now return */
> PG_RETURN_POINTER(result);
> }
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>
More information about the postgis-devel
mailing list