Method: FFI::AbstractMemory#get_bytes

Defined in:
ext/ffi_c/AbstractMemory.c

#get_bytes(offset, length) ⇒ String

Return string contained in memory.

Parameters:

  • offset (Integer)

    point in buffer to start from

  • length (Integer)

    string’s length in bytes.

Returns:

  • (String)

Raises:

  • (IndexError)

    if length is too great

  • (NullPointerError)

    if memory not initialized



544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'ext/ffi_c/AbstractMemory.c', line 544

static VALUE
memory_get_bytes(VALUE self, VALUE offset, VALUE length)
{
    AbstractMemory* ptr = MEMORY(self);
    long off, len;

    off = NUM2LONG(offset);
    len = NUM2LONG(length);

    checkRead(ptr);
    checkBounds(ptr, off, len);

    return rb_str_new((char *) ptr->address + off, len);
}