Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Created August 6, 2012 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckremes/3274964 to your computer and use it in GitHub Desktop.
Save chuckremes/3274964 to your computer and use it in GitHub Desktop.
require 'ffi'
module LibC
extend FFI::Library
library = ffi_lib(FFI::Library::LIBC).first
# memory allocators
attach_function :malloc, [:size_t], :pointer
end # module LibC
string = 'some string'
pointer = LibC.malloc(string.size + 1)
pointer.write_string(string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment