2 -----------------------------------------------------------------------------
3 This source file is part of GIMPACT Library.
5 For the latest info, see http://gimpact.sourceforge.net/
7 Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
8 email: projectileman@yahoo.com
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of EITHER:
12 (1) The GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 2.1 of the License, or (at
14 your option) any later version. The text of the GNU Lesser
15 General Public License is included with this library in the
16 file GIMPACT-LICENSE-LGPL.TXT.
17 (2) The BSD-style license that is included with this library in
18 the file GIMPACT-LICENSE-BSD.TXT.
19 (3) The zlib/libpng license that is included with this library in
20 the file GIMPACT-LICENSE-ZLIB.TXT.
22 This library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
25 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
27 -----------------------------------------------------------------------------
31 #include "gim_memory.h"
34 #ifdef GIM_SIMD_MEMORY
35 #include "LinearMath/btAlignedAllocator.h"
38 static gim_alloc_function *g_allocfn = 0;
39 static gim_alloca_function *g_allocafn = 0;
40 static gim_realloc_function *g_reallocfn = 0;
41 static gim_free_function *g_freefn = 0;
43 void gim_set_alloc_handler (gim_alloc_function *fn)
48 void gim_set_alloca_handler (gim_alloca_function *fn)
53 void gim_set_realloc_handler (gim_realloc_function *fn)
58 void gim_set_free_handler (gim_free_function *fn)
63 gim_alloc_function *gim_get_alloc_handler()
68 gim_alloca_function *gim_get_alloca_handler()
74 gim_realloc_function *gim_get_realloc_handler ()
80 gim_free_function *gim_get_free_handler ()
86 void * gim_alloc(size_t size)
91 ptr = g_allocfn(size);
95 #ifdef GIM_SIMD_MEMORY
96 ptr = btAlignedAlloc(size,16);
104 void * gim_alloca(size_t size)
106 if (g_allocafn) return g_allocafn(size); else return gim_alloc(size);
110 void * gim_realloc(void *ptr, size_t oldsize, size_t newsize)
112 void * newptr = gim_alloc(newsize);
113 size_t copysize = oldsize<newsize?oldsize:newsize;
114 gim_simd_memcpy(newptr,ptr,copysize);
119 void gim_free(void *ptr)
128 #ifdef GIM_SIMD_MEMORY