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)
|
||||
}
|
||||
|
||||
|
||||
@@ -716,12 +716,14 @@ pub fn (s string) free() {
|
||||
C.free(s.str)
|
||||
}
|
||||
|
||||
/*
|
||||
fn (arr []string) free() {
|
||||
for s in arr {
|
||||
s.free()
|
||||
}
|
||||
C.free(arr.data)
|
||||
}
|
||||
*/
|
||||
|
||||
// all_before('23:34:45.234', '.') == '23:34:45'
|
||||
pub fn (s string) all_before(dot string) string {
|
||||
|
||||
Reference in New Issue
Block a user