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

all: gc: provide optimized mode (#9716)

This commit is contained in:
Uwe Krüger
2021-04-14 00:40:26 +02:00
committed by GitHub
parent 8c95f07509
commit 10bf974cda
26 changed files with 11724 additions and 49 deletions

View File

@@ -302,7 +302,7 @@ pub fn realloc_data(old_data &byte, old_size int, new_size int) &byte {
// Unlike `v_calloc` vcalloc checks for negative values given in `n`.
pub fn vcalloc(n int) &byte {
if n < 0 {
panic('calloc(<=0)')
panic('calloc(<0)')
} else if n == 0 {
return &byte(0)
}
@@ -313,6 +313,24 @@ pub fn vcalloc(n int) &byte {
}
}
// special versions of the above that allocate memory which is not scanned
// for pointers (but is collected) when the Boehm garbage collection is used
pub fn vcalloc_noscan(n int) &byte {
$if gcboehm ? {
$if vplayground ? {
if n > 10000 {
panic('allocating more than 10 KB is not allowed in the playground')
}
}
if n < 0 {
panic('calloc(<0)')
}
return &byte(unsafe { C.memset(C.GC_MALLOC_ATOMIC(n), 0, n) })
} $else {
return unsafe { vcalloc(n) }
}
}
// free allows for manually freeing memory allocated at the address `ptr`.
[unsafe]
pub fn free(ptr voidptr) {