[][src]Struct samp::amx::Allocator

pub struct Allocator<'amx> { /* fields omitted */ }

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]

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]

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

impl<'_> Drop for Allocator<'_>[src]

Auto Trait Implementations

impl<'amx> !Send for Allocator<'amx>

impl<'amx> !Sync for Allocator<'amx>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

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

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

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

The type returned in the event of a conversion error.