Community articleMemory and string functions
Added by IBM contributorIBM on July 26, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

The API contains several memory and string functions that ensure cross-platform consistency in memory handling.
You should always use these functions when you are programming with the other functions in the API. The calls for these functions parallel the calls for the regular ANSI C functions, and you should refer to your ANSI C reference material for more complete explanations
ANSI C FunctionEquivalent API Function
freeFor strings: void cp_free(r_charP theString)

For other data: void pe_free(r_voidP theExistingMemory)
mallocFor strings: r_charP cp_malloc(rc_long theSize)

For other data: r_voidP pe_malloc(rc_long theSize)
memcpyvoid pe_memcpy(r_voidP theDest, rc_voidP theSrc, rc_long theSize)
reallocFor strings: r_charP cp_realloc(r_charP oldString, rc_long newSize, rc_long oldSize)

For other data: r_voidP pe_realloc(r_voidP theExistingMemory, rc_long theNewSize, rc_long theOldSize)

Note: This function takes three parameters, rather than the standard two.
strcatr_charP cp_strcat(r_charP theDest, rc_charP theSrc)
strchrr_charP cp_strchr(rc_charP theString, rc_char theChar)
strdupr_charP cp_strdup(rc_charP theString)
strcmpint cp_strcmp(r_charP string1, rc_charP string2)
strcpyr_charP cp_strcpy(r_charP theDest, rc_charP theSrc)
strlenrlong cp_strlen(r_charP theString)
strncmpint cp_strncmp(r_charP string1, r_charP string2, long n)
strrchrr_charP cp_strrchr(r_charP theString, rc_charP theChar)
strstrr_charP cp_strstr (r_charP theString, r_charP searchString)

Parent topic: C API