Skip to content

Commit b4de986

Browse files
committed
new Array method: get_allocated_bytes
1 parent 9b21917 commit b4de986

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/array.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use dim4::Dim4;
44
use defines::{AfError, DType, Backend};
55
use error::HANDLE_ERROR;
66
use util::{AfArray, DimT, HasAfEnum, MutAfArray, MutVoidPtr};
7-
use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_char};
7+
use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_ulong, c_char};
88
use std::ffi::CString;
99

1010
// Some unused functions from array.h in C-API of ArrayFire
@@ -100,6 +100,8 @@ extern {
100100
fn af_unlock_array(arr: AfArray) -> c_int;
101101

102102
fn af_get_device_ptr(ptr: MutVoidPtr, arr: AfArray) -> c_int;
103+
104+
fn af_get_allocated_bytes(result: *mut c_ulong, arr: AfArray) -> c_int;
103105
}
104106

105107
/// A multidimensional data container
@@ -405,6 +407,19 @@ impl Array {
405407
temp
406408
}
407409
}
410+
411+
/// Get the size of physical allocated bytes.
412+
///
413+
/// This function will return the size of the parent/owner if the current Array object is an
414+
/// indexed Array.
415+
pub fn get_allocated_bytes(&self) -> u64 {
416+
unsafe {
417+
let mut temp: u64 = 0;
418+
let err_val = af_get_allocated_bytes(&mut temp as *mut c_ulong, self.handle as AfArray);
419+
HANDLE_ERROR(AfError::from(err_val));
420+
temp
421+
}
422+
}
408423
}
409424

410425
/// Used for creating Array object from native resource id

0 commit comments

Comments
 (0)