Re: Persistence problem - Mailing list pgsql-general

From I. B.
Subject Re: Persistence problem
Date
Msg-id SNT128-W20BAE5D398E4C346BCDC1991FE0@phx.gbl
Whole thread Raw
In response to Re: Persistence problem  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

Thanks a lot for the patience and help. It worked.

Ivan


> To: i.bre@live.com
> CC: kleptog@svana.org; dalroi@solfertje.student.utwente.nl; pgsql-general@postgresql.org
> Subject: Re: [GENERAL] Persistence problem
> Date: Fri, 14 May 2010 18:34:14 -0400
> From: tgl@sss.pgh.pa.us
>
> "I. B." <i.bre@live.com> writes:
> > OK, here is the part of the code.
>
> Well, as suspected, you're doing this
>
> > typedef struct {
> > void *units;
> > } mapping_t;
>
> and this
>
> > units = (uPoint *) realloc(units, result->noOfUnits * sizeof(uPoint)); // EXPLAINED AT THE END OF THE POST
>
> which means that the array isn't contiguous with the mPoint struct.
> You can certainly do that and then rearrange things to make it so
> afterwards, but you're not doing so now. Personally though I'd avoid
> having two different representations. You'd be better off with
>
> typedef struct {
> int4 length;
> int noOfUnits;
> uPoint units[1]; /* actually, a variable length array */
> } mPoint;
>
> and then allocating or reallocating the result struct with a size
> calculation like this:
>
> offsetof(mPoint, units) + noOfUnits * sizeof(uPoint)
>
> BTW, realloc (as opposed to repalloc) doesn't seem like a tremendously
> good idea here. You are leaking that memory for the life of the session.
>
> regards, tom lane


Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now.

pgsql-general by date:

Previous
From: sunpeng
Date:
Subject: how to get Point * from datum =heap_getattr(....)?
Next
From: sunpeng
Date:
Subject: how to get Point * from datum =heap_getattr(....)?