1 /*
2     SuperCollider real time audio synthesis system
3     Copyright (c) 2002 James McCartney. All rights reserved.
4     http://www.audiosynth.com
5 
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.
10 
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.
15 
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
19 */
20 
21 
22 #include "InitAlloc.h"
23 
24 #include "malloc_aligned.hpp"
25 
26 AllocPool* pyr_pool_compile = nullptr;
27 AllocPool* pyr_pool_runtime = nullptr;
28 
29 #define AREASIZE 65536L
30 
pyr_new_area(size_t size)31 static void* pyr_new_area(size_t size) { return nova::malloc_aligned(size); }
32 
pyr_free_area(void * ptr)33 static void pyr_free_area(void* ptr) { nova::free_aligned(ptr); }
34 
pyr_new_area_from_runtime(size_t size)35 static void* pyr_new_area_from_runtime(size_t size) {
36     void* ptr = pyr_pool_runtime->Alloc(size);
37     MEMFAIL(ptr);
38     return ptr;
39 }
40 
pyr_free_area_from_runtime(void * ptr)41 static void pyr_free_area_from_runtime(void* ptr) { pyr_pool_runtime->Free(ptr); }
42 
pyr_init_mem_pools(int runtime_space,int runtime_grow)43 SCLANG_DLLEXPORT_C bool pyr_init_mem_pools(int runtime_space, int runtime_grow) {
44     pyr_pool_runtime = new AllocPool(pyr_new_area, pyr_free_area, runtime_space, runtime_grow);
45     if (!pyr_pool_runtime)
46         return false;
47 
48     pyr_pool_compile = new AllocPool(pyr_new_area_from_runtime, pyr_free_area_from_runtime, 0L, AREASIZE);
49     if (!pyr_pool_compile)
50         return false;
51 
52     // pyr_pool_runtime->DoCheckPool();
53 
54     return true;
55 }
56