Klasse Array

Alle implementierten Schnittstellen:
PointerInterface

public class Array extends Record
Contains the public fields of a GArray.

https://docs.gtk.org/glib/struct.Array.html

  • Felddetails

    • DATA

      public static final String DATA
      a pointer to the element data. The data may be moved as
      elements are added to the #GArray.
      Siehe auch:
    • LEN

      public static final String LEN
      the number of elements in the #GArray not including the
      possible terminating zero element.
      Siehe auch:
  • Konstruktordetails

  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • setFieldData

      public void setFieldData(Str data)
      a pointer to the element data. The data may be moved as
      elements are added to the #GArray.
    • getFieldData

      public Str getFieldData()
      a pointer to the element data. The data may be moved as
      elements are added to the #GArray.
    • setFieldLen

      public void setFieldLen(int len)
      the number of elements in the #GArray not including the
      possible terminating zero element.
    • getFieldLen

      public int getFieldLen()
      the number of elements in the #GArray not including the
      possible terminating zero element.
    • appendVals

      public static Array appendVals(@Nonnull Array array, @Nonnull Pointer data, int len)
      Adds @len elements onto the end of the array.
      Parameter:
      array - a #GArray
      data - a pointer to the elements to append to the end of the array
      len - the number of elements to append
      Gibt zurück:
      the #GArray
    • copy

      public static Array copy(@Nonnull Array array)
      Create a shallow copy of a #GArray. If the array elements consist of
      pointers to data, the pointers are copied but the actual data is not.
      Parameter:
      array - A #GArray.
      Gibt zurück:
      A copy of @array.
    • free

      public static Str free(@Nonnull Array array, boolean free_segment)
      Frees the memory allocated for the #GArray. If @free_segment is
      %TRUE it frees the memory block holding the elements as well. Pass
      %FALSE if you want to free the #GArray wrapper but preserve the
      underlying array for use elsewhere. If the reference count of
      @array is greater than one, the #GArray wrapper is preserved but
      the size of @array will be set to zero.

      If array contents point to dynamically-allocated memory, they should
      be freed separately if @free_segment is %TRUE and no @clear_func
      function has been set for @array.

      This function is not thread-safe. If using a #GArray from multiple
      threads, use only the atomic g_array_ref() and g_array_unref()
      functions.
      Parameter:
      array - a #GArray
      free_segment - if %TRUE the actual element data is freed as well
      Gibt zurück:
      the element data if @free_segment is %FALSE, otherwise %NULL. The element data should be freed using g_free().
    • getElementSize

      public static int getElementSize(@Nonnull Array array)
      Gets the size of the elements in @array.
      Parameter:
      array - A #GArray
      Gibt zurück:
      Size of each element, in bytes
    • insertVals

      public static Array insertVals(@Nonnull Array array, int index_, @Nullable Pointer data, int len)
      Inserts @len elements into a #GArray at the given index.

      If @index_ is greater than the array’s current length, the array is expanded.
      The elements between the old end of the array and the newly inserted elements
      will be initialised to zero if the array was configured to clear elements;
      otherwise their values will be undefined.

      If @index_ is less than the array’s current length, new entries will be
      inserted into the array, and the existing entries above @index_ will be moved
      upwards.

      @data may be %NULL if (and only if) @len is zero. If @len is zero, this
      function is a no-op.
      Parameter:
      array - a #GArray
      index_ - the index to place the elements at
      data - a pointer to the elements to insert
      len - the number of elements to insert
      Gibt zurück:
      the #GArray
    • _new

      public static Array _new(boolean zero_terminated, boolean clear_, int element_size)
      Creates a new #GArray with a reference count of 1.
      Parameter:
      zero_terminated - %TRUE if the array should have an extra element at the end which is set to 0
      clear_ - %TRUE if #GArray elements should be automatically cleared to 0 when they are allocated
      element_size - the size of each element in bytes
      Gibt zurück:
      the new #GArray
    • newTake

      public static Array newTake(@Nullable Pointer data, long len, boolean clear, long element_size)
      Creates a new #GArray with @data as array data, @len as length and a
      reference count of 1.

      This avoids having to copy the data manually, when it can just be
      inherited.
      After this call, @data belongs to the #GArray and may no longer be
      modified by the caller. The memory of @data has to be dynamically
      allocated and will eventually be freed with g_free().

      In case the elements need to be cleared when the array is freed, use
      g_array_set_clear_func() to set a #GDestroyNotify function to perform
      such task.

      Do not use it if @len or @element_size are greater than %G_MAXUINT.
      #GArray stores the length of its data in #guint, which may be shorter
      than #gsize.
      Parameter:
      data - an array of elements of @element_size, or %NULL for an empty array
      len - the number of elements in @data
      clear - %TRUE if #GArray elements should be automatically cleared to 0 when they are allocated
      element_size - the size of each element in bytes
      Gibt zurück:
      A new #GArray
    • newTakeZeroTerminated

      public static Array newTakeZeroTerminated(@Nonnull Pointer data, boolean clear, long element_size)
      Creates a new #GArray with @data as array data, computing the length of it
      and setting the reference count to 1.

      This avoids having to copy the data manually, when it can just be
      inherited.
      After this call, @data belongs to the #GArray and may no longer be
      modified by the caller. The memory of @data has to be dynamically
      allocated and will eventually be freed with g_free().

      The length is calculated by iterating through @data until the first %NULL
      element is found.

      In case the elements need to be cleared when the array is freed, use
      g_array_set_clear_func() to set a #GDestroyNotify function to perform
      such task.

      Do not use it if @data length or @element_size are greater than %G_MAXUINT.
      #GArray stores the length of its data in #guint, which may be shorter
      than #gsize.
      Parameter:
      data - an array of elements of @element_size
      clear - %TRUE if #GArray elements should be automatically cleared to 0 when they are allocated
      element_size - the size of each element in bytes
      Gibt zurück:
      A new #GArray
    • prependVals

      public static Array prependVals(@Nonnull Array array, @Nullable Pointer data, int len)
      Adds @len elements onto the start of the array.

      @data may be %NULL if (and only if) @len is zero. If @len is zero, this
      function is a no-op.

      This operation is slower than g_array_append_vals() since the
      existing elements in the array have to be moved to make space for
      the new elements.
      Parameter:
      array - a #GArray
      data - a pointer to the elements to prepend to the start of the array
      len - the number of elements to prepend, which may be zero
      Gibt zurück:
      the #GArray
    • ref

      public static Array ref(@Nonnull Array array)
      Atomically increments the reference count of @array by one.
      This function is thread-safe and may be called from any thread.
      Parameter:
      array - A #GArray
      Gibt zurück:
      The passed in #GArray
    • removeIndex

      public static Array removeIndex(@Nonnull Array array, int index_)
      Removes the element at the given index from a #GArray. The following
      elements are moved down one place.
      Parameter:
      array - a #GArray
      index_ - the index of the element to remove
      Gibt zurück:
      the #GArray
    • removeIndexFast

      public static Array removeIndexFast(@Nonnull Array array, int index_)
      Removes the element at the given index from a #GArray. The last
      element in the array is used to fill in the space, so this function
      does not preserve the order of the #GArray. But it is faster than
      g_array_remove_index().
      Parameter:
      array - a @GArray
      index_ - the index of the element to remove
      Gibt zurück:
      the #GArray
    • removeRange

      public static Array removeRange(@Nonnull Array array, int index_, int length)
      Removes the given number of elements starting at the given index
      from a #GArray. The following elements are moved to close the gap.
      Parameter:
      array - a @GArray
      index_ - the index of the first element to remove
      length - the number of elements to remove
      Gibt zurück:
      the #GArray
    • setClearFunc

      public static void setClearFunc(@Nonnull Array array, Array.OnDestroyNotify clear_func)
      Sets a function to clear an element of @array.

      The @clear_func will be called when an element in the array
      data segment is removed and when the array is freed and data
      segment is deallocated as well. @clear_func will be passed a
      pointer to the element to clear, rather than the element itself.

      Note that in contrast with other uses of #GDestroyNotify
      functions, @clear_func is expected to clear the contents of
      the array element it is given, but not free the element itself.
      <!-- language="C" -->
       typedef struct
       {
         gchar *str;
         GObject *obj;
       } ArrayElement;
       
       static void
       array_element_clear (ArrayElement *element)
       {
         g_clear_pointer (&element->str, g_free);
         g_clear_object (&element->obj);
       }
       
       // main code
       GArray *garray = g_array_new (FALSE, FALSE, sizeof (ArrayElement));
       g_array_set_clear_func (garray, (GDestroyNotify) array_element_clear);
       // assign data to the structure
       g_array_free (garray, TRUE);
       
      Parameter:
      array - A #GArray
      clear_func - a function to clear an element of @array
    • setSize

      public static Array setSize(@Nonnull Array array, int length)
      Sets the size of the array, expanding it if necessary. If the array
      was created with @clear_ set to %TRUE, the new elements are set to 0.
      Parameter:
      array - a #GArray
      length - the new size of the #GArray
      Gibt zurück:
      the #GArray
    • sizedNew

      public static Array sizedNew(boolean zero_terminated, boolean clear_, int element_size, int reserved_size)
      Creates a new #GArray with @reserved_size elements preallocated and
      a reference count of 1. This avoids frequent reallocation, if you
      are going to add many elements to the array. Note however that the
      size of the array is still 0.
      Parameter:
      zero_terminated - %TRUE if the array should have an extra element at the end with all bits cleared
      clear_ - %TRUE if all bits in the array should be cleared to 0 on allocation
      element_size - size of each element in the array
      reserved_size - number of elements preallocated
      Gibt zurück:
      the new #GArray
    • sort

      public static void sort(@Nonnull Array array, Array.OnCompareFunc compare_func)
      Sorts a #GArray using @compare_func which should be a qsort()-style
      comparison function (returns less than zero for first arg is less
      than second arg, zero for equal, greater zero if first arg is
      greater than second arg).

      This is guaranteed to be a stable sort since version 2.32.
      Parameter:
      array - a #GArray
      compare_func - comparison function
    • sortWithData

      public static void sortWithData(@Nonnull Array array, Array.OnCompareDataFunc compare_func, @Nullable Pointer user_data)
      Like g_array_sort(), but the comparison function receives an extra
      user data argument.

      This is guaranteed to be a stable sort since version 2.32.

      There used to be a comment here about making the sort stable by
      using the addresses of the elements in the comparison function.
      This did not actually work, so any such code should be removed.
      Parameter:
      array - a #GArray
      compare_func - comparison function
      user_data - data to pass to @compare_func
    • steal

      public static Pointer steal(@Nonnull Array array, @Nullable Int64 len)
      Frees the data in the array and resets the size to zero, while
      the underlying array is preserved for use elsewhere and returned
      to the caller.

      If the array was created with the @zero_terminate property
      set to %TRUE, the returned data is zero terminated too.

      If array elements contain dynamically-allocated memory,
      the array elements should also be freed by the caller.

      A short example of use:
      <!-- language="C" -->
       ...
       gpointer data;
       gsize data_len;
       data = g_array_steal (some_array, &data_len);
       ...
       
      Parameter:
      array - a #GArray.
      len - pointer to retrieve the number of elements of the original array
      Gibt zurück:
      the element data, which should be freed using g_free().
    • unref

      public static void unref(@Nonnull Array array)
      Atomically decrements the reference count of @array by one. If the
      reference count drops to 0, the effect is the same as calling
      g_array_free() with @free_segment set to %TRUE. This function is
      thread-safe and may be called from any thread.
      Parameter:
      array - A #GArray
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()