supernova: fix for small audio vector sizes
[supercollider.git] / lang / LangSource / InitAlloc.cpp
blob7be73106dabcebea744a35a17f5abdc45ff2f602
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "InitAlloc.h"
24 AllocPool *pyr_pool_compile = 0;
25 AllocPool *pyr_pool_runtime = 0;
27 #define HOST_ALLOC(size) malloc(size)
28 #define HOST_FREE(ptr) free((void*)(ptr))
30 #define AREASIZE 65536L
32 void* pyr_new_area(size_t size);
33 void* pyr_new_area(size_t size)
35 #ifdef SC_WIN32
36 size += kAlign;
37 char* ptr = (char*)malloc(size);
38 return (ptr + kAlign);
39 #else
40 return (char*)HOST_ALLOC(size);
41 #endif
44 void pyr_free_area(void *ptr);
45 void pyr_free_area(void *ptr)
47 #ifdef SC_WIN32
48 free((void*)((char*)ptr - kAlign));
49 #else
50 HOST_FREE(ptr);
51 #endif
54 void* pyr_new_area_from_runtime(size_t size);
55 void* pyr_new_area_from_runtime(size_t size)
57 void *ptr = pyr_pool_runtime->Alloc(size);
58 MEMFAIL(ptr);
59 return ptr;
62 void pyr_free_area_from_runtime(void *ptr);
63 void pyr_free_area_from_runtime(void *ptr)
65 pyr_pool_runtime->Free(ptr);
68 SC_DLLEXPORT_C bool pyr_init_mem_pools(int runtime_space, int runtime_grow)
70 pyr_pool_runtime = new AllocPool(pyr_new_area, pyr_free_area, runtime_space, runtime_grow);
71 if (!pyr_pool_runtime) return false;
73 pyr_pool_compile = new AllocPool(pyr_new_area_from_runtime, pyr_free_area_from_runtime, 0L, AREASIZE);
74 if (!pyr_pool_compile) return false;
76 //pyr_pool_runtime->DoCheckPool();
78 return true;