Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created June 29, 2012 15:11
Show Gist options
  • Save djberg96/3018498 to your computer and use it in GitHub Desktop.
Save djberg96/3018498 to your computer and use it in GitHub Desktop.
Problem initializing array of union
# It seems this is the wrong way to create an array of union in FFI. What's the right way?
array = []
# FileSegmentElement is an FFI::Union, and :Alignment is a :uint64
for i in 0...page_num
segment = FileSegmentElement.new
segment[:Alignment] = base_address + page_size * i
array << segment
end
# Add an extra element for null
array << FileSegmentElement.new
segment_array = FFI::MemoryPointer.new(FileSegmentElement, array.length)
segment_array.put_array_of_pointer(0, array)
# Seems to work but a call to ReadFileScatter simply returns "the parameter is incorrect".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment