From 8581c119004b496bb537dbf88c7f6444ab2ed245 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 14 Dec 2019 02:46:55 +0300 Subject: [PATCH] update malloc --- vlib/builtin/builtin.v | 6 ++---- vlib/compiler/main.v | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index c1f498b6ac..919c86e35e 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -108,20 +108,18 @@ pub fn malloc(n int) byteptr { if n < 0 { panic('malloc(<0)') } - /* - $if debug { + $if prealloc { res := g_m2_ptr g_m2_ptr += n nr_mallocs++ return res } $else { - */ ptr := C.malloc(n) if ptr == 0 { panic('malloc($n) failed') } return ptr - //} + } /* TODO #ifdef VPLAY diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index d176a791f9..79a5734ec1 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -230,6 +230,9 @@ pub fn (v mut V) compile() { cgen.genln('#define VDEBUG (1)') } } + if v.pref.prealloc { + cgen.genln('#define VPREALLOC (1)') + } if v.os == .js { cgen.genln('#define _VJS (1) ') }