Quantcast
Channel: Adobe Community : Popular Discussions - InDesign SDK
Viewing all articles
Browse latest Browse all 78596

PMString::substring

$
0
0

Hello people.

 

This is a general question about how best to write some code.

 

In my many projects I have lots of examples of this kind of code:

 

 

PMString *d, Data("SomeString of decent length");

d = Data.Substring(0, 12);

PMString newString = *d;

delete d;


This code could be simplified to something like this:

 

PMString newString,  Data("SomeString of decent length");

newString = *Data.Substring(0, 12);

 

but writing it this way leads to memory leaks (usually a good many of them).

 

Of course, one could simply use d as a pointer in the code, but one still needs to remember to delete the data after the program is finished with it.

 

Is there a more elegant way to deal with the return value of PMString::Substring in the InDesign SDK?

 

TIA!

 

John


Viewing all articles
Browse latest Browse all 78596


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>