Class NativeString


  • public final class NativeString
    extends Object
    Encapsulation of access to native strings.

    This class takes care of freeing the memory that was natively allocated for the string, if needed.

    Generally, any native API that returns "const char*" must not be freed, so in such cases the native return type mapping can actually be String rather than Pointer. Alternatively, copyNativeString(Pointer) can be used.

    Generally, Any native API that returns "char*" must be freed, so in such cases the native return type mapping must be Pointer and copyAndFreeNativeString(LibVlc, Pointer) must be used.

    Where a native string is contained in a Structure those strings should not be freed if the structure itself is subsequently freed (usually by a companion release native method), so in these cases copyNativeString(Pointer) must be used.

    • Method Detail

      • copyAndFreeNativeString

        public static final String copyAndFreeNativeString​(LibVlc libvlc,
                                                           com.sun.jna.Pointer pointer)
        Get a String from a native string pointer, freeing the native string pointer when done.

        If the native string pointer is not freed then a native memory leak will occur.

        Use this method if the native string type is "char*", i.e. lacking the "const" modifier.

        Parameters:
        libvlc - native library instance
        pointer - pointer to native string, may be null
        Returns:
        string, or null if the pointer was null
      • copyNativeString

        public static final String copyNativeString​(com.sun.jna.Pointer pointer)
        Copy a String from a native string pointer, without freeing the native pointer.

        Use this method if the native string type is "const char*".

        Parameters:
        pointer - pointer to native string, may be null
        Returns:
        string, or null if the pointer was null