[−][src]Struct samp::amx::Allocator
AMX memory allocator (on the heap) that frees captured memory after drop.
Methods
impl<'amx> Allocator<'amx>[src]
pub fn allot<T>(&self, init_value: T) -> Result<Ref<T>, AmxError> where
T: AmxPrimitive, [src]
T: AmxPrimitive,
Allocate memory for a primitive value.
Example
use samp_sdk::amx::Amx; // forward SomePublicFunc(player_id, &Float:health); let public_fn = amx.find_public("SomePublicFunc")?; let allocator = amx.allocator(); let float_ref = allocator.allot(1.2f32)?; let player_id = 10; amx.push(float_ref)?; amx.push(player_id)?; amx.exec(public_fn)?;
pub fn allot_buffer(&self, size: usize) -> Result<Buffer, AmxError>[src]
Allocate custom sized buffer on the heap.
Example
use samp_sdk::amx::Amx; // forward SomePublicFunc(player_id, ids[], size); let public_fn = amx.find_public("SomePublicFunc")?; let allocator = amx.allocator(); let size = 3; let mut buffer = allocator.allot_buffer(size)?; let player_id = 10; buffer[0] = 5; buffer[1] = 2; buffer[2] = 15; amx.push(size)?; amx.push(buffer)?; amx.push(player_id)?; amx.exec(public_fn)?;
pub fn allot_array<T>(&self, array: &[T]) -> Result<Buffer, AmxError> where
T: AmxCell<'amx> + AmxPrimitive, [src]
T: AmxCell<'amx> + AmxPrimitive,
Allocate an array on the heap, copy values from the passed array and return Buffer containing reference to the allocated cell.
Example
use samp_sdk::amx::Amx; // forward SomePublicFunc(player_id, ids[], size); let public_fn = amx.find_public("SomePublicFunc")?; let allocator = amx.allocator(); let buffer = allocator.allot_array(&[5, 2, 15])?; let player_id = 10; amx.push(buffer.len())?; amx.push(buffer)?; amx.push(player_id)?; amx.exec(public_fn)?;
pub fn allot_string(&self, string: &str) -> Result<AmxString, AmxError>[src]
Alocate a string, copy passed &str and return AmxString pointing to an Amx cell.
Example
use samp_sdk::amx::Amx; // forward SomePublicFunc(player_id, new_name[]); let public_fn = amx.find_public("SomePublicFunc")?; let allocator = amx.allocator(); let string = allocator.allot_string("hello")?; let player_id = 10; amx.push(string)?; amx.push(player_id)?; amx.exec(public_fn)?;
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
T: From<U>, [src]
T: From<U>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId[src]
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,