1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use ncnn_bind::*;

pub struct Allocator {
    ptr: ncnn_allocator_t,
}

impl Allocator {
    /// Creates a new pool allocator.
    ///
    /// # Safety
    ///
    /// Using the allocator when creating matrix results in a segmentation fault.
    pub unsafe fn new() -> crate::allocator::Allocator {
        Allocator {
            ptr: ncnn_allocator_create_pool_allocator(),
        }
    }

    /// Creates a new unlocked pool allocator.
    ///
    /// # Safety
    ///
    /// Using the allocator when creating matrix results in a segmentation fault.
    pub unsafe fn new_unlocked() -> crate::allocator::Allocator {
        Allocator {
            ptr: ncnn_allocator_create_unlocked_pool_allocator(),
        }
    }

    pub(crate) fn ptr(&self) -> ncnn_allocator_t {
        self.ptr
    }
}

impl Drop for Allocator {
    fn drop(&mut self) {
        unsafe {
            ncnn_allocator_destroy(self.ptr);
        }
    }
}