================
@@ -0,0 +1,21 @@
+#include <cstring>
+
+int main() {
+  constexpr char SINGLE_INSTANCE_STRING[] = "there_is_only_one_of_me";
+  constexpr size_t single_instance_size = sizeof(SINGLE_INSTANCE_STRING) + 1;
+  char *single_instance = new char[single_instance_size];
+  strcpy(single_instance, SINGLE_INSTANCE_STRING);
+
+  constexpr char DOUBLE_INSTANCE_STRING[] = "there_is_exactly_two_of_me";
+  constexpr size_t double_instance_size = sizeof(DOUBLE_INSTANCE_STRING) + 1;
+  char *double_instance = new char[double_instance_size];
+  char *double_instance_copy = new char[double_instance_size];
+  strcpy(double_instance, DOUBLE_INSTANCE_STRING);
+  strcpy(double_instance_copy, DOUBLE_INSTANCE_STRING);
----------------
clayborg wrote:

might be easier to use std::string here?
```
std::string str1("there_is_exactly_two_of_me");
std::string str2("there_is_exactly_two_of_me");
```
As long as more that 22 bytes are in the std::string, the string will live on 
the heap. Then you don't need to manually call strcpy and/or free it later.

https://github.com/llvm/llvm-project/pull/95007
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to