Re: Shared memory and memory context question

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: richard(dot)hills(at)balliol(dot)oxford(dot)ac(dot)uk
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Shared memory and memory context question
Date: 2006-02-05 14:11:25
Message-ID: 20060205141125.GA27019@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Feb 05, 2006 at 02:03:59PM +0000, richard(at)playford(dot)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(at)svana(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2006-02-05 14:15:58 Re: [PATCHES] Fix for running from admin account on win32
Previous Message richard 2006-02-05 14:03:59 Shared memory and memory context question