mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
builtin,cgen,markused: add struct @[aligned] support for structs allocated on the heap too (#24886)
This commit is contained in:
parent
f06def7d6d
commit
fa904c495e
14 changed files with 285 additions and 36 deletions
|
@ -5,8 +5,17 @@ module builtin
|
|||
@[unsafe]
|
||||
pub fn __malloc(size usize) voidptr {
|
||||
unsafe {
|
||||
return C.malloc(int(size))
|
||||
$if windows {
|
||||
// Warning! On windows, we always use _aligned_malloc to allocate memory.
|
||||
// This ensures that we can later free the memory with _aligned_free
|
||||
// without needing to track whether the memory was originally allocated
|
||||
// by malloc or _aligned_malloc.
|
||||
return C._aligned_malloc(size, 1)
|
||||
} $else {
|
||||
return C.malloc(int(size))
|
||||
}
|
||||
}
|
||||
return unsafe { nil }
|
||||
}
|
||||
|
||||
@[unsafe]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue