Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ode/ode-0.9/ode/src/memory.cpp @ 216

Last change on this file since 216 was 216, checked in by mathiask, 16 years ago

[Physik] add ode-0.9

File size: 2.5 KB
Line 
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
27
28static dAllocFunction *allocfn = 0;
29static dReallocFunction *reallocfn = 0;
30static dFreeFunction *freefn = 0;
31
32
33
34void dSetAllocHandler (dAllocFunction *fn)
35{
36  allocfn = fn;
37}
38
39
40void dSetReallocHandler (dReallocFunction *fn)
41{
42  reallocfn = fn;
43}
44
45
46void dSetFreeHandler (dFreeFunction *fn)
47{
48  freefn = fn;
49}
50
51
52dAllocFunction *dGetAllocHandler()
53{
54  return allocfn;
55}
56
57
58dReallocFunction *dGetReallocHandler()
59{
60  return reallocfn;
61}
62
63
64dFreeFunction *dGetFreeHandler()
65{
66  return freefn;
67}
68
69
70void * dAlloc (size_t size)
71{
72  if (allocfn) return allocfn (size); else return malloc (size);
73}
74
75
76void * dRealloc (void *ptr, size_t oldsize, size_t newsize)
77{
78  if (reallocfn) return reallocfn (ptr,oldsize,newsize);
79  else return realloc (ptr,newsize);
80}
81
82
83void dFree (void *ptr, size_t size)
84{
85  if (!ptr) return;
86  if (freefn) freefn (ptr,size); else free (ptr);
87}
Note: See TracBrowser for help on using the repository browser.