mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
-prealloc
This commit is contained in:
parent
88cde6e4e6
commit
ef562413cd
@ -108,18 +108,20 @@ pub fn malloc(n int) byteptr {
|
||||
if n < 0 {
|
||||
panic('malloc(<0)')
|
||||
}
|
||||
/*
|
||||
$if debug {
|
||||
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
|
||||
|
@ -82,6 +82,9 @@ fn (p mut Parser) comp_time() {
|
||||
else if name == 'debug' {
|
||||
p.comptime_if_block('VDEBUG')
|
||||
}
|
||||
else if name == 'prealloc' {
|
||||
p.comptime_if_block('VPREALLOC')
|
||||
}
|
||||
else if name == 'tinyc' {
|
||||
p.comptime_if_block('__TINYC__')
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ pub mut:
|
||||
vpath string
|
||||
x64 bool
|
||||
output_cross_c bool
|
||||
prealloc bool
|
||||
}
|
||||
|
||||
// Should be called by main at the end of the compilation process, to cleanup
|
||||
@ -419,7 +420,7 @@ fn (v mut V) generate_init() {
|
||||
// vlib can't have `init_consts()`
|
||||
v.cgen.genln('void init() {
|
||||
g_str_buf=malloc(1000);
|
||||
#if VDEBUG
|
||||
#if VPREALLOC
|
||||
g_m2_buf = malloc(50 * 1000 * 1000);
|
||||
g_m2_ptr = g_m2_buf;
|
||||
puts("allocated 50 mb");
|
||||
@ -528,7 +529,7 @@ pub fn (v mut V) generate_main() {
|
||||
cgen.genln(' main__main();')
|
||||
if !v.pref.is_bare {
|
||||
cgen.genln('free(g_str_buf);')
|
||||
cgen.genln('#if VDEBUG')
|
||||
cgen.genln('#if VPREALLOC')
|
||||
cgen.genln('free(g_m2_buf);')
|
||||
cgen.genln('puts("freed mem buf");')
|
||||
cgen.genln('#endif')
|
||||
@ -1076,6 +1077,7 @@ pub fn new_v(args[]string) &V {
|
||||
is_bare: '-freestanding' in args
|
||||
x64: '-x64' in args
|
||||
output_cross_c: '-output-cross-platform-c' in args
|
||||
prealloc: '-prealloc' in args
|
||||
is_repl: is_repl
|
||||
build_mode: build_mode
|
||||
cflags: cflags
|
||||
|
Loading…
Reference in New Issue
Block a user