[UI Sample] StringShare Sample Overview
The StringShare sample demonstrates how to store a string and use it in multiple places throughout a program.
The following log shows the result of the StringShare sample.
D/stringshare( 2975): The Cylons were created by man. D/stringshare( 2975): length : 31 D/stringshare( 2975): 12 Cylon models. 7 are known. 4 live in secret. 1 will be revealed. D/stringshare( 2975): There are many copies. And they have a plan
Implementation
The following code snippet demonstrates how to make a part of a string shared.
const char *str1, *str2; const char *prologe1 = "The Cylons were created by man. They rebelled. They evolved."; str1 = eina_stringshare_add_length(prologe1, 31);
The following code snippet demonstrates many ways of creating shared strings including an equivalent to sprint.
const char *prologe2 = "%d Cylon models. %d are known. %d live in secret. %d will be revealed."; str1 = eina_stringshare_printf(prologe2, 12, 7, 4, 1); const char *prologe3 = "There are many copies. And they have a plan"; str1 = eina_stringshare_nprintf(45, "%s", prologe3); str2 = eina_stringshare_add(prologe3); dlog_print(DLOG_DEBUG, LOG_TAG, "%s", str2);
The following code snippet demonstrates how to delete and increase the stringshare.
eina_stringshare_ref(str2); eina_stringshare_del(str1); eina_stringshare_del(str2);