tech.v3.datatype.native-buffer

Support for malloc/free and generalized support for reading/writing typed data to a long integer address of memory.

accessor-maps

alloc-uninitialized

(alloc-uninitialized dtype ec)(alloc-uninitialized dtype ec options)

Allocate an uninitialized buffer. See options for malloc.

alloc-zeros

(alloc-zeros dtype ec)(alloc-zeros dtype ec options)

Allocate a buffer of zeros. See options for malloc.

as-native-buffer

(as-native-buffer item)

If this item is convertible to a tech.v3.datatype.native_buffer.NativeBuffer return it. Return nil otherwise.

clone-native

(clone-native data options)(clone-native data)

Extremely fast clone assuming src is a native buffer. Exception otherwise. See options for malloc.

construct-binary-buffer

(construct-binary-buffer nbuf)

data->jvm

macro

(data->jvm value datatype swap?)

ensure-native

(ensure-native input outbuf)(ensure-native input)

If input is already a native buffer and has the same datatype as output, return input. Else copy input into output and return output.

free

(free data)

Free a long ptr. Malloc will do this for you. Calling this is probably a mistake.

jvm->data

macro

(jvm->data value datatype swap?)

malloc

(malloc n-bytes {:keys [resource-type uninitialized? endianness log-level datatype], :or {resource-type :auto}, :as dtype-or-opts})(malloc n-bytes)

Malloc memory. If a desired buffer type is needed follow up with set-native-datatype.

  • n-bytes - the number of bytes to malloc
  • opts - Either a keyword datatype or an options map.

Options:

  • :resource-type - defaults to :gc - maps to :track-type in tech.v3.resource/track but can also be set to nil in which case the data is not tracked this library will not clean it up.
  • :datatype - Datatype - defaults to :int8. Datatype byte width must evenly divide n-bytes.
  • :uninitialized? - do not initialize to zero. Use for perf in very very rare cases.
  • :endianness - Either :little-endian or :big-endian - defaults to platform.
  • :log-level - one of #{:debug :trace :info :warn :error :fatal} or nil if no logging is desired. When enabled allocations and frees will be logged in the same manner as tech.jna.

native-buffer->byte-array

(native-buffer->byte-array nbuf soff eoff)

native-buffer->map

(native-buffer->map buf)

Convert a native buffer to simple hashmap for printing or logging purposes.

native-buffer->string

(native-buffer->string nbuf off len)(native-buffer->string nbuf)

Convert a :int8 native buffer to a java string.

native-buffer-byte-len

(native-buffer-byte-len nb)

Get the length, in bytes, of a native buffer.

raw-read

(raw-read datatype swap?)

raw-write

(raw-write datatype swap?)

read-byte

(read-byte native-buffer offset)(read-byte native-buffer)

Ad-hoc read a byte at a given offset from a native buffer.

read-double

(read-double native-buffer offset)(read-double native-buffer)

Ad-hoc read a double at a given offset from a native buffer. This method is not endian-aware.

read-float

(read-float native-buffer offset)(read-float native-buffer)

Ad-hoc read a float at a given offset from a native buffer. This method is not endian-aware.

read-int

(read-int native-buffer offset)(read-int native-buffer)

Ad-hoc read an integer at a given offset from a native buffer. This method is not endian-aware.

read-long

(read-long native-buffer offset)(read-long native-buffer)

Ad-hoc read a long at a given offset from a native buffer. This method is not endian-aware.

read-short

(read-short native-buffer offset)(read-short native-buffer)

Ad-hoc read a short at a given offset from a native buffer. This method is not endian-aware.

set-endianness

(set-endianness item endianness)

Convert a native buffer to simple hashmap for printing or logging purposes.

set-gc-obj

(set-gc-obj nb gc-obj)

set-native-datatype

(set-native-datatype item datatype)

Set the datatype of a native buffer. n-elems will be recalculated.

set-parent

(set-parent buf new-parent)

Return a new native-buffer that references the same data but with a different parent object.

swap-value

macro

(swap-value value datatype swap?)

unsafe

(unsafe)

Get access to an instance of sun.misc.Unsafe.

wrap-address

(wrap-address address n-bytes datatype endianness gc-obj)(wrap-address address n-bytes gc-obj)(wrap-address address n-bytes)

Wrap a long interger address with a native buffer. gc-obj, if provided will be linked to the native buffer such that gc-obj will not be garbage collected before native buffer is garbage collected.

write-int

(write-int native-buffer offset val)

Ad-hoc write an integer at a given offset from a native buffer. This method is not endian-aware.

write-long

(write-long native-buffer offset val)

Ad-hoc write an integer at a given offset from a native buffer. This method is not endian-aware.