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:
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user