Back to index

glibc  2.9
Defines | Functions
tst-obstack.c File Reference
#include <obstack.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define obstack_chunk_alloc   verbose_malloc
#define obstack_chunk_free   verbose_free
#define ALIGN_BOUNDARY   64
#define ALIGN_MASK   (ALIGN_BOUNDARY - 1)
#define OBJECT_SIZE   1000

Functions

static void * verbose_malloc (size_t size)
static void verbose_free (void *buf)
int main (void)

Define Documentation

#define ALIGN_BOUNDARY   64

Definition at line 9 of file tst-obstack.c.

#define ALIGN_MASK   (ALIGN_BOUNDARY - 1)

Definition at line 10 of file tst-obstack.c.

#define OBJECT_SIZE   1000

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

Definition at line 7 of file tst-obstack.c.

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


Function Documentation

int main ( void  )

Definition at line 29 of file tst-obstack.c.

{
  int result = 0;
  int align = 2;

  while (align <= 64)
    {
      struct obstack obs;
      int i;
      int align_mask = align - 1;

      printf ("\n Alignment mask: %d\n", align_mask);

      obstack_init (&obs);
      obstack_alignment_mask (&obs) = align_mask;
      /* finish an empty object to take alignment into account */
      obstack_finish (&obs);

      /* let's allocate some objects and print their addresses */
      for (i = 15; i > 0; --i)
       {
         void *obj = obstack_alloc (&obs, OBJECT_SIZE);

         printf ("obstack_alloc (%u) => %p \t%s\n", OBJECT_SIZE, obj,
                ((uintptr_t) obj & align_mask) ? "(not aligned)" : "");
         result |= ((uintptr_t) obj & align_mask) != 0;
       }

      /* clean up */
      obstack_free (&obs, 0);

      align <<= 1;
    }

  return result;
}

Here is the call graph for this function:

static void verbose_free ( void *  buf) [static]

Definition at line 22 of file tst-obstack.c.

{
  free (buf);
  printf ("free (%p)\n", buf);
}

Here is the call graph for this function:

static void* verbose_malloc ( size_t  size) [static]

Definition at line 14 of file tst-obstack.c.

{
  void *buf = malloc (size);
  printf ("malloc (%zu) => %p\n", size, buf);
  return buf;
}

Here is the call graph for this function: