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