ode/src/memory.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*************************************************************************
       
     2  *                                                                       *
       
     3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
       
     4  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
       
     5  *                                                                       *
       
     6  * This library is free software; you can redistribute it and/or         *
       
     7  * modify it under the terms of EITHER:                                  *
       
     8  *   (1) The GNU Lesser General Public License as published by the Free  *
       
     9  *       Software Foundation; either version 2.1 of the License, or (at  *
       
    10  *       your option) any later version. The text of the GNU Lesser      *
       
    11  *       General Public License is included with this library in the     *
       
    12  *       file LICENSE.TXT.                                               *
       
    13  *   (2) The BSD-style license that is included with this library in     *
       
    14  *       the file LICENSE-BSD.TXT.                                       *
       
    15  *                                                                       *
       
    16  * This library is distributed in the hope that it will be useful,       *
       
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
       
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
       
    19  * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
       
    20  *                                                                       *
       
    21  *************************************************************************/
       
    22 
       
    23 #include <ode/config.h>
       
    24 #include <ode/memory.h>
       
    25 #include <ode/error.h>
       
    26 #include <ode/ode.h>
       
    27 
       
    28 
       
    29 EXPORT_C void dSetAllocHandler (dAllocFunction *fn)
       
    30 {
       
    31   GetGlobalData()->allocfn = fn;
       
    32 }
       
    33 
       
    34 
       
    35 EXPORT_C void dSetReallocHandler (dReallocFunction *fn)
       
    36 {
       
    37   GetGlobalData()->reallocfn = fn;
       
    38 }
       
    39 
       
    40 
       
    41 EXPORT_C void dSetFreeHandler (dFreeFunction *fn)
       
    42 {
       
    43   GetGlobalData()->freefn = fn;
       
    44 }
       
    45 
       
    46 
       
    47 EXPORT_C dAllocFunction *dGetAllocHandler()
       
    48 {
       
    49   return GetGlobalData()->allocfn;
       
    50 }
       
    51 
       
    52 
       
    53 EXPORT_C dReallocFunction *dGetReallocHandler()
       
    54 {
       
    55   return GetGlobalData()->reallocfn;
       
    56 }
       
    57 
       
    58 
       
    59 EXPORT_C dFreeFunction *dGetFreeHandler()
       
    60 {
       
    61   return GetGlobalData()->freefn;
       
    62 }
       
    63 
       
    64 
       
    65 EXPORT_C void * dAlloc (size_t size)
       
    66 {
       
    67   if (GetGlobalData()->allocfn) return GetGlobalData()->allocfn (size); else return malloc (size);
       
    68 }
       
    69 
       
    70 
       
    71 EXPORT_C void * dRealloc (void *ptr, size_t oldsize, size_t newsize)
       
    72 {
       
    73   if (GetGlobalData()->reallocfn) return GetGlobalData()->reallocfn (ptr,oldsize,newsize);
       
    74   else return realloc (ptr,newsize);
       
    75 }
       
    76 
       
    77 
       
    78 EXPORT_C void dFree (void *ptr, size_t size)
       
    79 {
       
    80   if (!ptr) return;
       
    81   if (GetGlobalData()->freefn) GetGlobalData()->freefn (ptr,size); else free (ptr);
       
    82 }