[Serusers] Re: [Serdev] what's the difference between the shm_malloc and pkg_malloc

Andrei Pelinescu-Onciul pelinescu-onciul at fokus.fraunhofer.de
Fri Mar 18 21:54:49 CET 2005


On Mar 16, 2005 at 17:08, szj <zjsun at biigroup.com> wrote:
> 
>  When I browse the ser code, I found there are three kind of memory
> allocation.The most frequently used is shm_malloc() and pkg_malloc().
>  the first have lock functions and the latter is not. I found that
> the transaction struct cell and its field is allocated with shm_alloc,
> but others are allocated with pkg_alloc(). I added a pointer member
> into the cell struct. If I allocate a block of memory for my pointer
> member with pkg_malloc(), the ser will crash when some one want to
> establish a call through ser.  If using shm_malloc(),all will go well.
>  What I want to know is when and where I should use shm_malloc() and
> pkg_malloc().

shm_malloc will alloc shared memory, that will be visible from other ser
 processes.
pkg_malloc will use "private", per process memory (it will not be
visible from other ser processes).

pkg_malloc is much faster (because it doesn't need locking).


If you need to alloc. something temporarily, or something that doesn't
need to be seen from another process use pkg_malloc.


Andrei




More information about the sr-users mailing list