commonlibsse_ng\re\i/
IMemoryStore.rs

1use crate::re::IMemoryStoreBase::{IMemoryStoreBase, IMemoryStoreBaseVtbl};
2use crate::re::offsets_rtti::RTTI_IMemoryStore;
3use crate::re::offsets_vtable::VTABLE_IMemoryStore;
4use crate::rel::id::VariantID;
5
6/// Memory store interface extending `IMemoryStoreBase`.
7#[repr(C)]
8#[derive(Debug, Clone, PartialEq)]
9pub struct IMemoryStore {
10    pub __base: IMemoryStoreBase,
11}
12const _: () = assert!(std::mem::size_of::<IMemoryStore>() == 0x8);
13
14impl Default for IMemoryStore {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl IMemoryStore {
21    /// Address & Offset of the runtime type information (RTTI) identifier.
22    pub const RTTI: VariantID = RTTI_IMemoryStore;
23
24    /// Address & Offset of the virtual function table.
25    pub const VTABLE: [VariantID; 1] = VTABLE_IMemoryStore;
26
27    pub const fn new() -> Self {
28        Self { __base: IMemoryStoreBase::new() }
29    }
30
31    /// Allocate aligned memory.
32    #[inline]
33    pub fn allocate_align(&mut self, size: usize, alignment: u32) -> *mut u8 {
34        unsafe { (self.vtable().AllocateAlignImpl)(self, size, alignment) }
35    }
36
37    /// Deallocate aligned memory.
38    #[inline]
39    pub fn deallocate_align(&mut self, block: &mut *mut u8) {
40        unsafe { (self.vtable().DeallocateAlignImpl)(self, block) }
41    }
42
43    /// Try allocating memory.
44    #[inline]
45    pub fn try_allocate(&mut self, size: usize, alignment: u32) -> *mut u8 {
46        unsafe { (self.vtable().TryAllocateImpl)(self, size, alignment) }
47    }
48
49    #[inline]
50    const fn vtable(&self) -> &'static IMemoryStoreVtbl {
51        unsafe { &*self.__base.vtable.cast::<IMemoryStoreVtbl>() }
52    }
53}
54
55/// Virtual table for `IMemoryStore`.
56#[repr(C)]
57pub struct IMemoryStoreVtbl {
58    pub __base: IMemoryStoreBaseVtbl,
59
60    pub AllocateAlignImpl:
61        unsafe extern "C" fn(this: *mut IMemoryStore, size: usize, alignment: u32) -> *mut u8,
62    pub DeallocateAlignImpl: unsafe extern "C" fn(this: *mut IMemoryStore, block: *mut *mut u8),
63    pub TryAllocateImpl:
64        unsafe extern "C" fn(this: *mut IMemoryStore, size: usize, alignment: u32) -> *mut u8,
65}