JuliaLang/julia — pull request #1063 by timholy (2012-07-17 22:32:19+00:00)
Title: Use a memio object and then pass the buffer externally

This should allow you to use a memio object, grab the buffer, and then pass it to an external program that has an appropriate "free" callback. Example usage:

s = memio(0, true, false)
for i = 1:1000; print(s, "Hi there"); end
buf, sz = takebuf_raw(s)
ccall(:somefunction, RetVal, (SomeArgTypes, Ptr{Void}, Uint, Ptr{Void}), SomeArgVals, buf, sz, :jl_free1)

You'd use ``:jl_free1`` if the "free" callback function syntax is

void freefunc(void *p)

and ``:jl_free2`` if the callback syntax is

void freefunc(void *p, void *arg)

This obviously doesn't cover every single possibility, but it should get the large majority.