Re: How to allocate space to structure instance

Поиск
Список
Период
Сортировка
От amul sul
Тема Re: How to allocate space to structure instance
Дата
Msg-id 1386747438.63157.YahooMailNeo@web193504.mail.sg3.yahoo.com
обсуждение исходный текст
Ответ на Re: How to allocate space to structure instance  (Rohit Goyal <rhtgyl.87@gmail.com>)
Список pgsql-novice
>Can you please tel me the location in code where 

>I can allocate space before begin transaction call?
Its in your code.  your case it may be spi_connect(). 

> Right now, I am using spi_palloc function to alloctae memory to my structure instance

Ohh, but spi_palloc should work as you expected. I am not sure why you losing it.


>I want to insert 10 rows in a table and want to store the corresponding transaction ID in >one link list.
I am not sure is right method or not, why dont you allocated memory of structure in top context when your code start.


spi_connect()
/*
*
* SOME CODE
*/
oldcontext = CurrentMemoryContext;
        oldowner = CurrentResourceOwner;

 MemoryContextSwitchTo(mycontext);
 // Allocate memory for your structure.
 
MemoryContextSwitchTo(oldcontext);
        CurrentResourceOwner = oldowner; 
/*
*
* SOME CODE
*/
spi_finish();

let say, here mycontext is when main function of application called, you should store it as mycontext
=  CurrentMemoryContext;

I am not sure is this best practice, but it work for me.

Regards,
Amul Sul


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

Предыдущее
От: Rohit Goyal
Дата:
Сообщение: Re: How to allocate space to structure instance
Следующее
От: Gerald Cheves
Дата:
Сообщение: PostgreSQL Studio