Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

alloc.c

Go to the documentation of this file.
00001 /*
00002  * alloc.c
00003  * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
00004  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
00005  *
00006  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
00007  * See http://libmpeg2.sourceforge.net/ for updates.
00008  *
00009  * mpeg2dec is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * mpeg2dec is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 #include "config.h"
00025 
00026 #include <stdlib.h>
00027 #include <inttypes.h>
00028 
00029 #include "mpeg2.h"
00030 #include "mpeg2_internal.h"
00031 
00032 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
00033 /* some systems have memalign() but no declaration for it */
00034 void * memalign (size_t align, size_t size);
00035 #endif
00036 
00037 void * (* mpeg2_malloc_hook) (int size, int reason) = NULL;
00038 int (* mpeg2_free_hook) (void * buf) = NULL;
00039 
00040 void * mpeg2_malloc (int size, int reason)
00041 {
00042     char * buf;
00043 
00044     if (mpeg2_malloc_hook) {
00045         buf = (char *) mpeg2_malloc_hook (size, reason);
00046         if (buf)
00047             return buf;
00048     }
00049 
00050 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
00051     return memalign (16, size);
00052 #else
00053     buf = (char *) malloc (size + 15 + sizeof (void **));
00054     if (buf) {
00055         char * align_buf;
00056 
00057         align_buf = buf + 15 + sizeof (void **);
00058         align_buf -= (long)align_buf & 15;
00059         *(((void **)align_buf) - 1) = buf;
00060         return align_buf;
00061     }
00062     return NULL;
00063 #endif
00064 }
00065 
00066 void mpeg2_free (void * buf)
00067 {
00068     if (mpeg2_free_hook && mpeg2_free_hook (buf))
00069         return;
00070 
00071 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
00072     free (buf);
00073 #else
00074     free (*(((void **)buf) - 1));
00075 #endif
00076 }
 

Powered by Plone

This site conforms to the following standards: