Back to index

glibc  2.9
Defines | Functions | Variables
tst-trim1.c File Reference
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define N   10000
#define TEST_FUNCTION   do_test ()

Functions

static int do_test (void)

Variables

static void * arr [N]

Define Documentation

#define N   10000

Definition at line 6 of file tst-trim1.c.

#define TEST_FUNCTION   do_test ()

Definition at line 55 of file tst-trim1.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 11 of file tst-trim1.c.

{
  for (int i = 0; i < N; ++i)
    {
      size_t size = random () % 16384;

      if ((arr[i] = malloc (size)) == NULL)
       {
       nomem:
         puts ("not enough memory");
         return 0;
       }

      memset (arr[i], size, size);
    }

  void *p = malloc (256);
  if (p == NULL)
    goto nomem;
  memset (p, 1, 256);

  puts ("==================================================================");

  for (int i = 0; i < N; ++i)
    if (i % 13 != 0)
      free (arr[i]);

  puts ("==================================================================");

  malloc_trim (0);

  puts ("==================================================================");

  p = malloc (30000);
  if (p == NULL)
    goto nomem;

  memset (p, 2, 30000);

  malloc_trim (0);

  return 0;
}

Here is the call graph for this function:


Variable Documentation

void* arr[N] [static]

Definition at line 8 of file tst-trim1.c.