Malloc

Class to allocate raw memory.  It is used to store the data of Sequence and MultiArray.  Malloc is faster than Ruby’s String because the memory is not cleared.  Access is not safeguarded against memory violations and the memory size is unknown after constructing the object.

See also

Summary
MallocClass to allocate raw memory.
Functions
Malloc.newConstructor.
_dumpThrows an exception because Malloc does not support marshalling.
inspectReturn string with information about this object.
midExtract part of the data.
assignOverwrite part of the data.

Functions

Malloc.new

def Malloc.new(size)

Constructor.

The size of the memory must be divisible by the length of the value string or else.

Parameters

sizesize of memory to allocate

_dump

def _dump

Throws an exception because Malloc does not support marshalling.

inspect

def inspect

Return string with information about this object.

Returns

Something like this: “Malloc(0x8b1a10)”

mid

def mid(offset,
length)

Extract part of the data.

Data is copied from memory and returned as a string.

Parameters

offsetstarting offset to copy data from
lengthamount of data to copy

Returns

A string containing the data.

assign

def assign(offset,
data)

Overwrite part of the data.

The data in the string is copied to memory.

Parameters

offsetstarting offset to write data to
dataRuby string containing the data
def Malloc.new(size)
Constructor.
def _dump
Throws an exception because Malloc does not support marshalling.
def inspect
Return string with information about this object.
def mid(offset,
length)
Extract part of the data.
def assign(offset,
data)
Overwrite part of the data.
def Sequence(element_type,  
num_elements,  
stride =  element_type.size)
Create an array class.
def MultiArray(element_type,
*shape)
Create a multi-dimensional array class.
Objects of this class are used internally to store native data.
Close