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

free arrays when they are out of scope

main.v: update help
This commit is contained in:
Alexander Medvednikov
2019-07-21 12:43:47 +02:00
parent 385f1c856e
commit 40c31f701f
5 changed files with 53 additions and 35 deletions

View File

@ -5,13 +5,15 @@
module builtin
struct array {
is_slice bool
pub:
// Using a void pointer allows to implement arrays without generics and without generating
// extra code for every type.
pub:
data voidptr
len int
cap int
element_size int
}
// Private function, used by V (`nums := []int`)
@ -144,6 +146,7 @@ pub fn (s array) slice(start, _end int) array {
data: s.data + start * s.element_size
len: l
cap: l
is_slice: true
}
return res
}
@ -215,7 +218,11 @@ pub fn (a []int) str() string {
return res
}
pub fn (a []int) free() {
//pub fn (a []int) free() {
pub fn (a array) free() {
if a.is_slice {
return
}
C.free(a.data)
}