outputting to MEM with the C API for CLI algorithms

Chris Toney via gdal-dev <[email protected]>
Newsgroups gmane.comp.gis.gdal.devel
Message-ID <CALRbqOTfn36eAkGVupHh4FR3dCKoxXiJotzriusQetMVXDwhQg@mail.gmail.com>
Hi,
In "How to use gdal CLI algorithms from C"
(https://gdal.org/en/latest/programs/gdal_cli_from_c.html):

>When outputting to a MEM -- In Memory datasets dataset, you typically want to get the output dataset with:

>GDALAlgorithmArgH hArg = GDALAlgorithmGetArg(hAlg, "output");
>GDALArgDatasetValueH hVal = GDALAlgorithmArgGetAsDatasetValue(hArg);
>GDALDatasetH hDS = GDALArgDatasetValueGetDatasetRef(hVal);

But if we use GDALArgDatasetValueGetDatasetRef(hValue):

>This does not modify the reference counter, hence the lifetime of the returned object is not guaranteed to exceed the one of hValue.

Is there anything wrong with the following, if we want the lifetime of
the returned object to exceed that of hValue?

GDALDatasetH hDS = nullptr;
hDS = GDALArgDatasetValueGetDatasetIncreaseRefCount(hArgDSValue);
if (!hDS) {
    GDALArgDatasetValueRelease(hArgDSValue);
    // ...
}
// ...
GDALArgDatasetValueRelease(hArgDSValue);

and then continue using the MEM hDS?

That's been working fine, but I'm wondering why the specific note in
the tutorial about outputting to MEM in that way?

Thanks.

Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.