unify heap allocation handling
This commit is contained in:
parent
63dfecdbf5
commit
fd6f9198f3
10 changed files with 101 additions and 110 deletions
13
src/lib.rs
13
src/lib.rs
|
|
@ -34,6 +34,7 @@ pub use crate::command::*;
|
|||
pub use crate::connection::*;
|
||||
pub use crate::cp437_grid::*;
|
||||
pub use crate::packet::*;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
mod bitmap;
|
||||
mod bitvec;
|
||||
|
|
@ -49,3 +50,15 @@ use std::time::Duration;
|
|||
|
||||
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
|
||||
pub const SP_FRAME_PACING_MS: u128 = Duration::from_millis(30).as_millis();
|
||||
|
||||
pub(crate) fn heap_move<T>(x: T) -> *mut T {
|
||||
Box::into_raw(Box::new(x))
|
||||
}
|
||||
|
||||
pub(crate) fn heap_move_nonnull<T>(x: T) -> NonNull<T> {
|
||||
NonNull::from(Box::leak(Box::new(x)))
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn heap_drop<T>(x: NonNull<T>) {
|
||||
drop(unsafe { Box::from_raw(x.as_ptr()) });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue