mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
freestanding: malloc/free with mm_alloc an mm_free
Added more array support that depends on malloc. Added string clone (that uses malloc). Added test for it. Eliminated stack allocated buffers from most of the unit checks.
This commit is contained in:

committed by
Alexander Medvednikov

parent
6ec626c5e9
commit
8178e1f7da
@ -34,3 +34,21 @@ fn (a mut array) set(i int, val voidptr) {
|
||||
}
|
||||
mem_copy(a.data + a.element_size * i, val, a.element_size)
|
||||
}
|
||||
|
||||
|
||||
// array.repeat returns new array with the given array elements
|
||||
// repeated `nr_repeat` times
|
||||
pub fn (a array) repeat(nr_repeats int) array {
|
||||
assert nr_repeats >= 0
|
||||
|
||||
arr := array {
|
||||
len: nr_repeats * a.len
|
||||
cap: nr_repeats * a.len
|
||||
element_size: a.element_size
|
||||
data: malloc(nr_repeats * a.len * a.element_size)
|
||||
}
|
||||
for i := 0; i < nr_repeats; i++ {
|
||||
mem_copy(arr.data + i * a.len * a.element_size, a.data, a.len * a.element_size)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
Reference in New Issue
Block a user