C
copx
Can you / are you supposed to free() string literals which are no longer
needed?
In my case I've menu construction code that looks like this:
menu_items = list_new();
list_add(menu_items, "Item 1");
list_add(menu_items, "Item 2");
list_add(menu_items, "Item 3");
menu_create(menu_items, false)
The boolean argument of menu_create() determines whether or not the entries
of the menu_items list (a generic linked-list) are free()ed on destruction.
AFAIK string literals decay into char pointers but aren't supposed to be
free()ed, however I'm not sure.
IIRC string literals remain in memory until program termination.
In my current project I've lots of string literals which are only
temporarily needed and I'm afraid of wasting lots of RAM...
Any ideas?
needed?
In my case I've menu construction code that looks like this:
menu_items = list_new();
list_add(menu_items, "Item 1");
list_add(menu_items, "Item 2");
list_add(menu_items, "Item 3");
menu_create(menu_items, false)
The boolean argument of menu_create() determines whether or not the entries
of the menu_items list (a generic linked-list) are free()ed on destruction.
AFAIK string literals decay into char pointers but aren't supposed to be
free()ed, however I'm not sure.
IIRC string literals remain in memory until program termination.
In my current project I've lots of string literals which are only
temporarily needed and I'm afraid of wasting lots of RAM...
Any ideas?