#[repr(transparent)]pub struct CoTaskMem;Expand description
CoTaskMemAlloc / CoTaskMemRealloc / CoTaskMemFree
Uses the default COM / “OLE task memory” allocator provided by CoGetMalloc, which in turn simply uses Heap* functions under the hood.
Consider using Heap directly instead, unless you’re specifically doing COM / have documentation mandating a specific (de)allocator for interop purpouses.
| Rust | C |
|---|---|
thin::Alloc::alloc_uninit | CoTaskMemAlloc [1] |
thin::Realloc::realloc_uninit | CoTaskMemRealloc [2] |
thin::Free::free | CoTaskMemFree |
size/layoutof 0 bytes will allocate successfullynew_size/new_layout.size()of 0 bytes will go through alloc+free instead
§References
IMalloc(stateful equivalent)- Memory Allocation in COM (learn.microsoft.com)
Trait Implementations§
Source§impl Alloc for CoTaskMem
Safety Item Description
align✔️ Validated via thin::test::alignment
size✔️ Validated via thin::test::edge_case_sizes
pin✔️ CoTaskMem is 'static - allocations by CoTaskMemAlloc live until CoTaskMemRealloced or CoTaskMemFreed
compatible✔️ CoTaskMem uses exclusively intercompatible fns
exclusive✔️ Allocations by CoTaskMemAlloc are exclusive/unique
exceptions✔️ CoTaskMemAlloc returns null on error per docs / lack of HEAP_GENERATE_EXCEPTIONS. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior.
threads✔️ CoTaskMemAlloc uses a no-init gCMalloc::Alloc → HeapAlloc with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood
zeroed✔️ Validated via thin::test::zeroed_alloc, trivial default impl
impl Alloc for CoTaskMem
| Safety Item | Description |
|---|---|
align | ✔️ Validated via thin::test::alignment |
size | ✔️ Validated via thin::test::edge_case_sizes |
pin | ✔️ CoTaskMem is 'static - allocations by CoTaskMemAlloc live until CoTaskMemRealloced or CoTaskMemFreed |
compatible | ✔️ CoTaskMem uses exclusively intercompatible fns |
exclusive | ✔️ Allocations by CoTaskMemAlloc are exclusive/unique |
exceptions | ✔️ CoTaskMemAlloc returns null on error per docs / lack of HEAP_GENERATE_EXCEPTIONS. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior. |
threads | ✔️ CoTaskMemAlloc uses a no-init gCMalloc::Alloc → HeapAlloc with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood |
zeroed | ✔️ Validated via thin::test::zeroed_alloc, trivial default impl |
Source§impl Alloc for CoTaskMem
impl Alloc for CoTaskMem
Source§fn alloc_uninit(
&self,
layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
fn alloc_uninit( &self, layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
impl Copy for CoTaskMem
impl Eq for CoTaskMem
Source§impl Free for CoTaskMem
Safety Item Description
compatible✔️ CoTaskMem uses exclusively intercompatible fns
exceptions✔️ CoTaskMemFree is “infalliable”. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior.
threads✔️ CoTaskMemFree uses a no-init gCMalloc::Free → HeapFree with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood
impl Free for CoTaskMem
| Safety Item | Description |
|---|---|
compatible | ✔️ CoTaskMem uses exclusively intercompatible fns |
exceptions | ✔️ CoTaskMemFree is “infalliable”. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior. |
threads | ✔️ CoTaskMemFree uses a no-init gCMalloc::Free → HeapFree with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood |
Source§unsafe fn free_nullable(&self, ptr: *mut MaybeUninit<u8>)
unsafe fn free_nullable(&self, ptr: *mut MaybeUninit<u8>)
Source§impl Meta for CoTaskMem
impl Meta for CoTaskMem
Source§const ZST_SUPPORTED: bool = true
const ZST_SUPPORTED: bool = true
CoTaskMemAlloc(0)allocates successfully.CoTaskMemRealloc(ptr, 0)frees. Note thatthin::Reallocandfat::Reallocresolve this by going through alloc + free for 0 bytes.
Source§const MAX_ALIGN: Alignment = super::MEMORY_ALLOCATION_ALIGNMENT
const MAX_ALIGN: Alignment = super::MEMORY_ALLOCATION_ALIGNMENT
Indicates the maximum alignment this allocator should be expected to succeed in allocating.
Requesting an allocation with more alignment than this is almost certainly a bug. Read more
Source§impl Ord for CoTaskMem
impl Ord for CoTaskMem
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for CoTaskMem
impl PartialOrd for CoTaskMem
Source§impl Realloc for CoTaskMem
Safety Item Description
align⚠️ untested, but should be safe if thin::Alloc was
size⚠️ untested, but should be safe if thin::Alloc was
pin✔️ CoTaskMem is 'static - reallocations by CoTaskMemRealloc live until CoTaskMemRealloced again or CoTaskMemFreed
compatible✔️ CoTaskMem uses exclusively intercompatible fns
exclusive✔️ Allocations by CoTaskMemRealloc are exclusive/unique
exceptions✔️ CoTaskMemRealloc returns null on error per docs / lack of HEAP_GENERATE_EXCEPTIONS. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior.
threads✔️ CoTaskMemRealloc uses a no-init gCMalloc::Realloc → HeapRealloc with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood
zeroed✔️ Trivial Err / not supported
preserved⚠️ untested, but should be the case…
impl Realloc for CoTaskMem
| Safety Item | Description |
|---|---|
align | ⚠️ untested, but should be safe if thin::Alloc was |
size | ⚠️ untested, but should be safe if thin::Alloc was |
pin | ✔️ CoTaskMem is 'static - reallocations by CoTaskMemRealloc live until CoTaskMemRealloced again or CoTaskMemFreed |
compatible | ✔️ CoTaskMem uses exclusively intercompatible fns |
exclusive | ✔️ Allocations by CoTaskMemRealloc are exclusive/unique |
exceptions | ✔️ CoTaskMemRealloc returns null on error per docs / lack of HEAP_GENERATE_EXCEPTIONS. Non-unwinding fatalish heap corruption exceptions will only occur after previous undefined behavior. |
threads | ✔️ CoTaskMemRealloc uses a no-init gCMalloc::Realloc → HeapRealloc with dwFlags=0 (e.g. not using HEAP_NO_SERIALIZE) under the hood |
zeroed | ✔️ Trivial Err / not supported |
preserved | ⚠️ untested, but should be the case… |
Source§const CAN_REALLOC_ZEROED: bool = false
const CAN_REALLOC_ZEROED: bool = false
Indicate if
realloc_zeroed is supported / likely to work.Source§unsafe fn realloc_uninit(
&self,
ptr: NonNull<MaybeUninit<u8>>,
new_size: usize,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_uninit( &self, ptr: NonNull<MaybeUninit<u8>>, new_size: usize, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
Source§unsafe fn realloc_zeroed(
&self,
_ptr: NonNull<MaybeUninit<u8>>,
_new_size: usize,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_zeroed( &self, _ptr: NonNull<MaybeUninit<u8>>, _new_size: usize, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
Source§impl Realloc for CoTaskMem
impl Realloc for CoTaskMem
Source§unsafe fn realloc_uninit(
&self,
ptr: NonNull<MaybeUninit<u8>>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_uninit( &self, ptr: NonNull<MaybeUninit<u8>>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
Source§unsafe fn realloc_zeroed(
&self,
ptr: NonNull<MaybeUninit<u8>>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
unsafe fn realloc_zeroed( &self, ptr: NonNull<MaybeUninit<u8>>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<MaybeUninit<u8>>, Self::Error>
impl Stateless for CoTaskMem
impl StructuralPartialEq for CoTaskMem
impl ZstSupported for CoTaskMem
Auto Trait Implementations§
impl Freeze for CoTaskMem
impl RefUnwindSafe for CoTaskMem
impl Send for CoTaskMem
impl Sync for CoTaskMem
impl Unpin for CoTaskMem
impl UnsafeUnpin for CoTaskMem
impl UnwindSafe for CoTaskMem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more