2025-03-08 11:04:18 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
|
|
|
|
use pin_init::*;
|
|
|
|
|
|
|
|
// Struct with size over 1GiB
|
|
|
|
#[derive(Debug)]
|
2025-05-23 14:54:11 +02:00
|
|
|
#[allow(dead_code)]
|
2025-03-08 11:04:18 +00:00
|
|
|
pub struct BigStruct {
|
|
|
|
buf: [u8; 1024 * 1024 * 1024],
|
|
|
|
a: u64,
|
|
|
|
b: u64,
|
|
|
|
c: u64,
|
|
|
|
d: u64,
|
|
|
|
managed_buf: ManagedBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ManagedBuf {
|
|
|
|
buf: [u8; 1024 * 1024],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ManagedBuf {
|
|
|
|
pub fn new() -> impl Init<Self> {
|
2025-05-23 16:50:57 +02:00
|
|
|
init!(ManagedBuf { buf <- init_zeroed() })
|
2025-03-08 11:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2025-05-23 14:54:11 +02:00
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
|
|
{
|
|
|
|
// we want to initialize the struct in-place, otherwise we would get a stackoverflow
|
|
|
|
let buf: Box<BigStruct> = Box::init(init!(BigStruct {
|
2025-05-23 16:50:57 +02:00
|
|
|
buf <- init_zeroed(),
|
2025-05-23 14:54:11 +02:00
|
|
|
a: 7,
|
|
|
|
b: 186,
|
|
|
|
c: 7789,
|
|
|
|
d: 34,
|
|
|
|
managed_buf <- ManagedBuf::new(),
|
|
|
|
}))
|
|
|
|
.unwrap();
|
|
|
|
println!("{}", core::mem::size_of_val(&*buf));
|
|
|
|
}
|
2025-03-08 11:04:18 +00:00
|
|
|
}
|