The STRDUP macro is a platform-independent substitute for the C library routine strdup. This macro creates a new copy of a string in the request’s memory pool. The memory can be explicitly freed by a call to FREE. If the memory is not explicitly freed, it is automatically freed after processing the current request. If pooled memory has been disabled in the configuration file with the built-in pool-initSAF, PERM_STRDUP and STRDUP both obtain their memory from the system heap. However, because the memory allocated by STRDUP is automatically freed, do not share this memory between threads.
The STRDUP routine is functionally equivalent to:
newstr = (char *) MALLOC(strlen(str) + 1); strcpy(newstr, str); |
char *STRDUP(char *ptr);
A pointer to the new string.
char *ptr is a pointer to a string.
char *name1 = "MyName"; char *name2 = STRDUP(name1);
CALLOC() Macro,MALLOC() Macro, FREE() Macro, REALLOC() Macro, PERM_STRDUP() Macro