Skip to content

Instantly share code, notes, and snippets.

@twadleigh
Last active August 29, 2015 14:11
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 twadleigh/7c08ef7bac671604ebeb to your computer and use it in GitHub Desktop.
Save twadleigh/7c08ef7bac671604ebeb to your computer and use it in GitHub Desktop.
# init file with test data: bytes of 0, 1, 2, ..
fn = "tmp.dat"
open(fn, "w") do s
write(s, UInt8[i-1 for i in 1:256])
end
import Base.read
# define an immutable type and a read
immutable A
a :: UInt32
b :: UInt16
end
function read(s::IO, ::Type{A})
a = ntoh(read(s, UInt32))
b = ntoh(read(s, UInt16))
A(a, b)
end
print("sizeof A: ", sizeof(A), "\n")
# test read footprint
open(fn, "r") do s
seekstart(s)
a1 = read(s, A)
p1 = position(s)
print(a1, "\n")
print("Bytes read for single value: ", p1, "\n")
seekstart(s)
a2 = read(s, A, 1)
p2 = position(s)
print(a2, "\n")
print("Bytes read per value for array: ", p2, "\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment