Struct windows_permissions::localheap::LocalBox[][src]

pub struct LocalBox<T> { /* fields omitted */ }
Expand description

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

Get a LocalBox from a NonNull

Safety

  • The NonNull pointer must have been allocated with a Windows API call. When the resulting NonNull<T> is dropped, it will be dropped with LocalFree
  • The buffer pointed to by the pointer must be a valid T

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.

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.

Get a pointer to the underlying data structure

Use this when interacting with FFI libraries that want pointers.

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.