1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: parametrize g_str_buf size by V_STRBUF_MB; free in _vcleanup()

This commit is contained in:
Delyan Angelov 2020-06-30 16:30:02 +03:00
parent 55989b3c2c
commit af56b01a41

View File

@ -10,6 +10,7 @@ import v.pref
import v.token
import v.util
import v.depgraph
import os
// NB: keywords after 'new' are reserved in C++
const (
@ -2762,8 +2763,9 @@ fn (mut g Gen) write_init_function() {
}
if g.pref.autofree {
// Pre-allocate the string buffer
// TODO make it configurable
g.writeln('g_str_buf = malloc(1024 * 1000);')
s_str_buf_size := os.getenv('V_STRBUF_MB')
mb_size := if s_str_buf_size == '' { 1 } else { s_str_buf_size.int() }
g.writeln('g_str_buf = malloc( ${mb_size} * 1024 * 1000 );')
}
g.writeln('\tbuiltin_init();')
g.writeln('\tvinit_string_literals();')
@ -2785,6 +2787,7 @@ fn (mut g Gen) write_init_function() {
g.writeln('void _vcleanup() {')
// g.writeln('puts("cleaning up...");')
g.writeln(g.cleanups.str())
g.writeln('\tfree(g_str_buf);')
g.writeln('}')
if g.pref.printfn_list.len > 0 && '_vcleanup' in g.pref.printfn_list {
println(g.out.after(fn_vcleanup_start_pos))