(root)/
glib-2.79.0/
glib/
tests/
memchunk.c
       1  /* GLIB - Library of useful routines for C programming
       2   * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
       3   *
       4   * SPDX-License-Identifier: LGPL-2.1-or-later
       5   *
       6   * This library is free software; you can redistribute it and/or
       7   * modify it under the terms of the GNU Lesser General Public
       8   * License as published by the Free Software Foundation; either
       9   * version 2.1 of the License, or (at your option) any later version.
      10   *
      11   * This library is distributed in the hope that it will be useful,
      12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14   * Lesser General Public License for more details.
      15   *
      16   * You should have received a copy of the GNU Lesser General Public
      17   * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      18   */
      19  
      20  /*
      21   * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
      22   * file for a list of people on the GLib Team.  See the ChangeLog
      23   * files for a list of changes.  These files are distributed with
      24   * GLib at ftp://ftp.gtk.org/pub/gtk/.
      25   */
      26  
      27  /* We are testing some deprecated APIs here */
      28  #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
      29  #define GLIB_DISABLE_DEPRECATION_WARNINGS
      30  #endif
      31  
      32  #include <glib.h>
      33  
      34  static void
      35  test_basic (void)
      36  {
      37    G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      38  
      39    GMemChunk *mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
      40    gchar *mem[10000];
      41    guint i;
      42    for (i = 0; i < 10000; i++)
      43      {
      44        guint j;
      45        mem[i] = g_chunk_new (gchar, mem_chunk);
      46        for (j = 0; j < 50; j++)
      47  	mem[i][j] = i * j;
      48      }
      49    for (i = 0; i < 10000; i++)
      50      g_mem_chunk_free (mem_chunk, mem[i]);
      51  
      52    g_mem_chunk_destroy (mem_chunk);
      53  
      54    G_GNUC_END_IGNORE_DEPRECATIONS
      55  }
      56  
      57  int
      58  main (int   argc,
      59        char *argv[])
      60  {
      61    g_test_init (&argc, &argv, NULL);
      62  
      63    g_test_add_func ("/memchunk/basic", test_basic);
      64  
      65    return g_test_run ();
      66  }