[Kamailio-Devel] Creating shared memory during runtime
Iñaki Baz Castillo
ibc at aliax.net
Fri Jan 9 19:29:11 CET 2009
El Viernes, 9 de Enero de 2009, Daniel-Constantin Mierla escribió:
> Hello,
>
> no, it won't work. you have to allocate a pointer where to store the
> pointer.
Thanks a lot. Please let me some questions inline:
> 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;
^------------ why is this needed? 'string' already was '*address'.
> shm_free(string);
> string = shm_malloc(sizeof(char) * 200);
> *address = string;
> // Store some new value in 'string'.
> }
If I'm not wrong, the memory after mod_init() and the memory after
mi_function() would be something as:
Memory after mod_init():
----------------------------------------------------------
1000 | pointer 'address' | "4000"
4000 | pointer 'string' | "hello world"
... |
4099 |
----------------------------------------------------------
Memory after mi_function():
----------------------------------------------------------
1000 | pointer 'address' | "7000"
7000 | pointer 'string' | "hello again, now I'm longer!"
... |
... |
... |
... |
7199 |
----------------------------------------------------------
This means that when a process wants to read 'string' value (*string) they
must access it via *address value (**address), is it?
Thanks a lot.
--
Iñaki Baz Castillo
More information about the Devel
mailing list