Struct windows_permissions::localheap::LocalBox [−][src]
pub struct LocalBox<T> { /* fields omitted */ }
A smart pointer to an object on the local heap.
Windows has several different options for allocation, and the local heap is
no longer recommended. However, several of the
WinAPI calls in this crate use the local heap, allocating with LocalAlloc
and freeing with LocalFree
. This type encapsulates that behavior,
representing objects that reside on the local heap.
It is primarily created using unsafe
code in the wrappers
crate when
the WinAPI allocates a data structure for the program (using from_raw
).
However, allocations can be manually made with allocate
or try_allocate
.
For example:
use std::mem::size_of; use windows_permissions::LocalBox; let mut local_ptr1: LocalBox<u32> = unsafe { LocalBox::allocate() }; let mut local_ptr2: LocalBox<u32> = unsafe { LocalBox::try_allocate(true, size_of::<u32>()).unwrap() }; *local_ptr1 = 5u32; *local_ptr2 = 5u32; assert_eq!(local_ptr1, local_ptr2);
For details, see MSDN.
Exotically-sized types
This struct has not been tested with exotically-sized types. Use with extreme caution.
Implementations
impl<T> LocalBox<T>
[src]
pub unsafe fn from_raw(ptr: NonNull<T>) -> Self
[src]
Get a LocalBox
from a NonNull
Requirements
- The
NonNull
pointer must have been allocated with a Windows API call. When the resultingNonNull<T>
is dropped, it will be dropped withLocalFree
- The buffer pointed to by the pointer must be a valid
T
pub unsafe fn allocate() -> Self
[src]
Allocate enough zeroed memory to hold a T
with LocalAlloc
The memory will always come back zeroed, which has a modest performance penalty but can reduce the impact of buffer overruns.
Panics
Panics if the underlying LocalAlloc
call fails.
Safety
The allocated memory is zeroed, which may not be a valid representation
of a T
.
pub unsafe fn try_allocate(zeroed: bool, size: usize) -> Result<Self>
[src]
Allocate memory with LocalAlloc
If the allocation fails, returns the error code.
Safety
The contents of the memory are not guaranteed to be a valid T
. The
contents will either be zeroed or uninitialized depending on the zeroed
parameter.
Additionally, size
should be large enough to contain a T
.
pub fn as_ptr(&self) -> *mut T
[src]
Get a pointer to the underlying data structure
Use this when interacting with FFI libraries that want pointers.
Trait Implementations
impl<T> AsRef<T> for LocalBox<T>
[src]
impl<T: Debug> Debug for LocalBox<T>
[src]
impl<T> Deref for LocalBox<T>
[src]
impl<T> DerefMut for LocalBox<T>
[src]
impl<T: Display> Display for LocalBox<T>
[src]
impl<T> Drop for LocalBox<T>
[src]
impl FromStr for LocalBox<SecurityDescriptor>
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl FromStr for LocalBox<Sid>
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl<T, U> PartialEq<LocalBox<U>> for LocalBox<T> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
Auto Trait Implementations
impl<T> RefUnwindSafe for LocalBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for LocalBox<T>
impl<T> !Sync for LocalBox<T>
impl<T> Unpin for LocalBox<T>
impl<T> UnwindSafe for LocalBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,