Re: Persistence problem

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Persistence problem
Дата
Msg-id 24615.1273876454@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Persistence problem  ("I. B." <i.bre@live.com>)
Ответы Re: Persistence problem  ("I. B." <i.bre@live.com>)
Список pgsql-general
"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

В списке pgsql-general по дате отправления:

Предыдущее
От: "I. B."
Дата:
Сообщение: Re: Persistence problem
Следующее
От: Stephen Frost
Дата:
Сообщение: Re: Poor query performance on one of two "like" databases in production.