[][src]Function rustacuda::memory::cuda_malloc_locked

pub unsafe fn cuda_malloc_locked<T>(count: usize) -> CudaResult<*mut T>

Unsafe wrapper around the cuMemAllocHost function, which allocates some page-locked host memory and returns a raw pointer pointing to it. The memory is not cleared.

Note that count is in units of T; thus a count of 3 will allocate 3 * size_of::<T>() bytes of memory.

Memory buffers allocated using cuda_malloc_locked must be freed using cuda_free_locked.

Errors

If allocating memory fails, returns the CUDA error value. If the number of bytes to allocate is zero (either because count is zero or because T is a zero-sized type), or if the size of the allocation would overflow a usize, returns InvalidValue.

Safety

Since the allocated memory is not initialized, the caller must ensure that it is initialized before reading from it in any way. Additionally, the caller must ensure that the memory allocated is freed using cuda_free_locked, or the memory will be leaked.

Examples

use rustacuda::memory::*;
unsafe {
    // Allocate space for 5 u64s
    let locked_buffer = cuda_malloc_locked::<u64>(5).unwrap();
    cuda_free_locked(locked_buffer).unwrap();
}