basis.memory

Data

abstract class Data extends AnyRef

A byte-addressed memory region.

Address Space

Data objects have a 64-bit address space ranging from 0 until size. Each address in the space identifies a unique storage location for a single Byte value. Multi-byte values occupy multiple storage locations and thus have multiple addresses–one address per byte. The lowest address of a multi-byte sequence canonically refers to the whole byte sequence.

N-byte divisible addresses are said to be N-byte aligned. Using aligned addresses reduces some multi-byte memory accesses to single array operations, which can improve performance. Alignment sensitive allocators, such as the default Data allocator, try to allocate memory backed by a primitive array whose element size matches the alignment of the struct values it will store. This allocation strategy, combined with proper address alignment, enables an optimal code path when serializaing many values.

Aligned memory accesses truncate unaligned addresses to their required alignment.

Value Types

Data objects store structured value types. Structs model value types as transformations between instance types and fixed-length byte sequences, with a restriction on address alignment.

Primitive types have dedicated load and store methods, with multi-byte primitives declaring aligned and unaligned variants. A Data object's endian property specifies the byte order used to interpret multi-byte values.

Example:
  1. scala> val data = Data.alloc[Int](1L) // allocate data for a single Int value.
    data: basis.memory.Data = Data4LE(4) // the runtime Data class may vary.
    
    scala> data.storeInt(0L, 0xCAFEBABE) // store an Int value to address 0.
    
    scala> data.loadInt(0L).toHexString // load an Int value from address 0.
    res1: String = cafebabe
    
    scala> data.loadByte(0L).toHexString // load the low byte of the Int value.
    res2: String = ffffffbe // the least significant byte comes first in this case.
    
    scala> data.loadShort(2L).toHexString // load the high bytes of the Int value.
    res3: String = ffffcafe // toHexString sign extends the result to an Int.
    
    scala> data.loadShort(1L).toHexString // load an unaligned address.
    res4: String = ffffbabe // the address was truncated, oops.
    
    scala> data.loadUnalignedShort(1L).toHexString // load the unaligned middle bytes of the Int value.
    res5: String = fffffeba
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Data
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Data()

Abstract Value Members

  1. abstract def copy(size: Long = this.size): Data

    Returns a resized copy of this data.

    Returns a resized copy of this data.

    size

    the number of bytes to copy.

    returns

    the copied data.

  2. abstract def endian: Endianness

    Returns the internal byte order.

  3. abstract def loadByte(address: Long): Byte

    Loads a single byte.

    Loads a single byte.

    address

    the address to load.

    returns

    the loaded Byte value.

  4. abstract def size: Long

    Returns the size in bytes of the address space.

  5. abstract def storeByte(address: Long, value: Byte): Unit

    Stores a single byte.

    Stores a single byte.

    address

    the storage address.

    value

    the Byte value to store.

  6. abstract def unit: Int

    Returns the internal word size.

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clear(fromAddress: Long, untilAddress: Long): Unit

    Zeros a range of addresses.

    Zeros a range of addresses.

    fromAddress

    the lower bound of the address range.

    untilAddress

    the excluded upper bound of the address range.

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  9. def copyToArray[T](address: Long, array: Array[T], start: Int, count: Int)(implicit T: Struct[T]): Unit

    Copies a sequence of loaded struct values to an array slice.

    Copies a sequence of loaded struct values to an array slice.

    T

    the instance type to load.

    address

    the aligned address to load.

    array

    the array to copy to.

    start

    the offset to copy to in the array.

    count

    the number of values to copy.

    T

    the implicit struct type to load.

  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  13. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. def load[T](address: Long)(implicit T: Struct[T]): T

    Loads an instance from a struct value.

    Loads an instance from a struct value.

    T

    the instance type to load.

    address

    the aligned address to load.

    T

    the implicit struct type to load.

    returns

    the loaded instance.

    Annotations
    @macroImpl()
  17. def load2[T1, T2, R](address: Long)(f: (T1, T2) ⇒ R)(implicit T1: Struct[T1], T2: Struct[T2]): R

    Loads and unpacks a struct as two values.

    Loads and unpacks a struct as two values.

    Annotations
    @macroImpl()
  18. def load3[T1, T2, T3, R](address: Long)(f: (T1, T2, T3) ⇒ R)(implicit T1: Struct[T1], T2: Struct[T2], T3: Struct[T3]): R

    Loads and unpacks a struct as three values.

    Loads and unpacks a struct as three values.

    Annotations
    @macroImpl()
  19. def load4[T1, T2, T3, T4, R](address: Long)(f: (T1, T2, T3, T4) ⇒ R)(implicit T1: Struct[T1], T2: Struct[T2], T3: Struct[T3], T4: Struct[T4]): R

    Loads and unpacks a struct as four values.

    Loads and unpacks a struct as four values.

    Annotations
    @macroImpl()
  20. def loadArray[T](address: Long, count: Int)(implicit T: Struct[T]): Array[T]

    Loads a sequence of struct values into a new array.

    Loads a sequence of struct values into a new array.

    T

    the instance type to load.

    address

    the aligned address to load.

    count

    the number of values to load.

    T

    the implicit struct type to load.

    returns

    the loaded array of instance values.

  21. def loadDouble(address: Long): Double

    Loads an 8-byte endian ordered word as a native-endian Double value.

    Loads an 8-byte endian ordered word as a native-endian Double value. Truncates address to 8-byte alignment.

    address

    the 8-byte aligned address to load.

    returns

    the loaded Double value.

  22. def loadFloat(address: Long): Float

    Loads a 4-byte endian ordered word as a native-endian Float value.

    Loads a 4-byte endian ordered word as a native-endian Float value. Truncates address to 4-byte alignment.

    address

    the 4-byte aligned address to load.

    returns

    the loaded Float value.

  23. def loadInt(address: Long): Int

    Loads a 4-byte endian ordered word as a native-endian Int value.

    Loads a 4-byte endian ordered word as a native-endian Int value. Truncates address to 4-byte alignment.

    address

    the 4-byte aligned address to load.

    returns

    the loaded Int value.

  24. def loadLong(address: Long): Long

    Loads an 8-byte endian ordered word as a native-endian Long value.

    Loads an 8-byte endian ordered word as a native-endian Long value. Truncates address to 8-byte alignment.

    address

    the 8-byte aligned address to load.

    returns

    the loaded Long value.

  25. def loadShort(address: Long): Short

    Loads a 2-byte endian ordered word as a native-endian Short value.

    Loads a 2-byte endian ordered word as a native-endian Short value. Truncates address to 2-byte alignment.

    address

    the 2-byte aligned address to load.

    returns

    the loaded Short value.

  26. def loadUnalignedDouble(address: Long): Double

    Loads an 8-byte endian ordered word as a native-endian Double value.

    Loads an 8-byte endian ordered word as a native-endian Double value.

    address

    the unaligned address to load.

    returns

    the loaded Double value.

  27. def loadUnalignedFloat(address: Long): Float

    Loads a 4-byte endian ordered word as a native-endian Float value.

    Loads a 4-byte endian ordered word as a native-endian Float value.

    address

    the unaligned address to load.

    returns

    the loaded Float value.

  28. def loadUnalignedInt(address: Long): Int

    Loads a 4-byte endian ordered word as a native-endian Int value.

    Loads a 4-byte endian ordered word as a native-endian Int value.

    address

    the unaligned address to load.

    returns

    the loaded Int value.

  29. def loadUnalignedLong(address: Long): Long

    Loads an 8-byte endian ordered word as a native-endian Long value.

    Loads an 8-byte endian ordered word as a native-endian Long value.

    address

    the unaligned address to load.

    returns

    the loaded Long value.

  30. def loadUnalignedShort(address: Long): Short

    Loads a 2-byte endian ordered word as a native-endian Short value.

    Loads a 2-byte endian ordered word as a native-endian Short value.

    address

    the unaligned address to load.

    returns

    the loaded Short value.

  31. def move(fromAddress: Long, toAddress: Long, size: Long): Unit

    Moves a byte range to a new, potentially overlapping address.

    Moves a byte range to a new, potentially overlapping address.

    fromAddress

    the address to copy from.

    toAddress

    the address to copy to.

    size

    the number of bytes to copy.

  32. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  33. final def notify(): Unit

    Definition Classes
    AnyRef
  34. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  35. def store[T](address: Long, value: T)(implicit T: Struct[T]): Unit

    Stores an instance as a struct value.

    Stores an instance as a struct value.

    T

    the instance type to store.

    address

    the aligned storage address.

    value

    the instance to store.

    T

    the implicit struct type to store.

    Annotations
    @macroImpl()
  36. def store2[T1, T2](address: Long)(value1: T1, value2: T2)(implicit T1: Struct[T1], T2: Struct[T2]): Unit

    Packs and stores two values as a struct.

    Packs and stores two values as a struct.

    Annotations
    @macroImpl()
  37. def store3[T1, T2, T3](address: Long)(value1: T1, value2: T2, value3: T3)(implicit T1: Struct[T1], T2: Struct[T2], T3: Struct[T3]): Unit

    Packs and stores three values as a struct.

    Packs and stores three values as a struct.

    Annotations
    @macroImpl()
  38. def store4[T1, T2, T3, T4](address: Long)(value1: T1, value2: T2, value3: T3, value4: T4)(implicit T1: Struct[T1], T2: Struct[T2], T3: Struct[T3], T4: Struct[T4]): Unit

    Packs and stores four values as a struct.

    Packs and stores four values as a struct.

    Annotations
    @macroImpl()
  39. def storeArray[T](address: Long, array: Array[T], start: Int, count: Int)(implicit T: Struct[T]): Unit

    Stores an array slice as a sequence of struct values.

    Stores an array slice as a sequence of struct values.

    T

    the instance type to store.

    address

    the aligned storage address.

    array

    the array to store from.

    start

    the offset to store from in the array.

    count

    the number of values to store.

    T

    the implicit struct type to store.

  40. def storeDouble(address: Long, value: Double): Unit

    Stores a native-endian Double value as an 8-byte endian ordered word.

    Stores a native-endian Double value as an 8-byte endian ordered word. Truncates address to 8-byte alignment.

    address

    the 8-byte aligned storage address.

    value

    the Double value to store.

  41. def storeFloat(address: Long, value: Float): Unit

    Stores a native-endian Float value as a 4-byte endian ordered word.

    Stores a native-endian Float value as a 4-byte endian ordered word. Truncates address to 4-byte alignment.

    address

    the 4-byte aligned storage address.

    value

    the Float value to store.

  42. def storeInt(address: Long, value: Int): Unit

    Stores a native-endian Int value as a 4-byte endian ordered word.

    Stores a native-endian Int value as a 4-byte endian ordered word. Truncates address to 4-byte alignment.

    address

    the 4-byte aligned storage address.

    value

    the Int value to store.

  43. def storeLong(address: Long, value: Long): Unit

    Store a native-endian Long value as an 8-byte endian ordered word.

    Store a native-endian Long value as an 8-byte endian ordered word. Truncates address to 8-byte alignment.

    address

    the 8-byte aligned storage address.

    value

    the Long value to store.

  44. def storeShort(address: Long, value: Short): Unit

    Stores a native-endian Short value as a 2-byte endian ordered word.

    Stores a native-endian Short value as a 2-byte endian ordered word. Truncates address to 2-byte alignment.

    address

    the 2-byte aligned storage address.

    value

    the Short value to store.

  45. def storeUnalignedDouble(address: Long, value: Double): Unit

    Stores a native-endian Double value as an 8-byte endian ordered word.

    Stores a native-endian Double value as an 8-byte endian ordered word.

    address

    the unaligned storage address.

    value

    the Double value to store.

  46. def storeUnalignedFloat(address: Long, value: Float): Unit

    Stores a native-endian Float value as a 4-byte endian ordered word.

    Stores a native-endian Float value as a 4-byte endian ordered word.

    address

    the unaligned storage address.

    value

    the Float value to store.

  47. def storeUnalignedInt(address: Long, value: Int): Unit

    Stores a native-endian Int value as a 4-byte endian ordered word.

    Stores a native-endian Int value as a 4-byte endian ordered word.

    address

    the unaligned storage address.

    value

    the Int value to store.

  48. def storeUnalignedLong(address: Long, value: Long): Unit

    Stores a native-endian Long value as an 8-byte endian ordered word.

    Stores a native-endian Long value as an 8-byte endian ordered word.

    address

    the unaligned storage address.

    value

    the Long value to store.

  49. def storeUnalignedShort(address: Long, value: Short): Unit

    Stores a native-endian Short value as a 2-byte endian ordered word.

    Stores a native-endian Short value as a 2-byte endian ordered word.

    address

    the unaligned storage address.

    value

    the Short value to store.

  50. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  51. def toString(): String

    Definition Classes
    AnyRef → Any
  52. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  53. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  54. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any

General properties

Loading and storing aligned primitive values

Loading and storing unaligned primitive values

Loading and storing compound values

Loading and storing arrays of values

Bulk transfer operations

Ungrouped