Re: Shared memory and memory context question

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Shared memory and memory context question
Дата
Msg-id 20060205141125.GA27019@svana.org
обсуждение исходный текст
Ответ на Shared memory and memory context question  (richard@playford.net)
Ответы Re: Shared memory and memory context question  (Richard Hills <richard@playford.net>)
Список pgsql-hackers
On Sun, Feb 05, 2006 at 02:03:59PM +0000, richard@playford.net wrote:
> 1. Change memory context to TopMemoryContext and palloc everything there.
> (However, I believe this still isn't shared between processes?)

Not shared, correct.

> 2. Use the shmem functions in src/backend/storage/ipc/shmem.c to create a
> chunk of shared memory and use this (Although I would like to avoid writing
> my own memory manager to carve up the space).

This is the generally accepted method. Please remember that when
sharing structures you have to worry about concurrency. So you need
locking.

> 3. Somehow create shared memory using the shmem functions, and set a memory
> context to live *inside* this shared memory, which my trigger functions can
> then switch to. Then use palloc() and pfree() without worrying..

Nope, palloc/pfree don't deal with concurrency.

> Please let me know if this problem has been solved before, as I have searched
> through the mailing lists and through the source, but am not sure which is
> the best way to resolve it. Thanks for your help.

Most people allocate chunks of shared memory and don't use
palloc/pfree. What are you doing that requires such management? Most
shared structures in PostgreSQL are allocated once and never freed...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

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

Предыдущее
От: richard@playford.net
Дата:
Сообщение: Shared memory and memory context question
Следующее
От: "Magnus Hagander"
Дата:
Сообщение: Re: [PATCHES] Fix for running from admin account on win32