malloc-byte-array ( byte-array -- alien ) (original) (raw)

Vocabulary
alien.data

Inputs

byte-array a byte-array

Outputs

alien an alien

Word description
Allocates an unmanaged memory block of the same size as the byte array, and copies the contents of the byte array there.

Warning
Don't forget to deallocate the memory with a call to free.

Errors
Throws an error if memory allocation fails.

Definition

USING: alien kernel libc ;

IN: alien.data

: malloc-byte-array ( byte-array -- alien )
binary-object [ nip malloc dup ] 2keep memcpy ;