[Kamailio-Devel] Creating shared memory during runtime
Daniel-Constantin Mierla
miconda at gmail.com
Fri Jan 9 18:51:31 CET 2009
Hello,
no, it won't work. you have to allocate a pointer where to store the
pointer.
char **address;
char *string;
static int mod_init(void)
{
address = shm_malloc(sizeof(char*));
string = shm_malloc(sizeof(char) * 100);
*address = string;
// Store some value in 'string'.
}
static struct mi_root* mi_function(struct mi_root* cmd_tree, void* param) {
string = *address;
shm_free(string);
string = shm_malloc(sizeof(char) * 200);
*address = string;
// Store some new value in 'string'.
}
And you probably have to think about races and use some locking mechanism.
Cheers,
Daniel
On 01/09/2009 07:36 PM, Iñaki Baz Castillo wrote:
> Hi, if a Kamailio process (i.e. via a MI function) frees a shm variable and
> creates it again (so it would be now allocated in a memory different position
> and have a different size), will the rest of Kamailio running processes
> realize of it?
>
> This is:
>
> ---------------------
> char *string;
>
> static int mod_init(void)
> {
> string = shm_malloc(sizeof(char) * 100);
> // Store some value in 'string'.
> }
>
> static struct mi_root* mi_function(struct mi_root* cmd_tree, void* param) {
> shm_free(string);
> string = shm_malloc(sizeof(char) * 200);
> // Store some new value in 'string'.
> }
> ---------------------
>
> Will it work?
> If not, how could achieve it? Must I reserve the max possible size
> in "mod_init()" and use the same pointer all the time during runtime?
>
> Thanks.
>
>
>
--
Daniel-Constantin Mierla
http://www.asipto.com
More information about the Devel
mailing list