Hello julia-users,

I maintain a package that wraps a C++ library. One feature of this library
is called "tables". These tables are a widely used data format in my field
and they can store arrays of ints, floats, doubles, complex<float>s, and
strings (the library defines a custom string type but it can be easily
converted to char*).

My usual procedure for reading these arrays is to query the type and size
of the array and then read them into Julia by ccalling a function

void read_float_array(Table* table, char* name, float* output, int length)
{ ... }

where `table` is the table we are reading from, `name` is the name of the
array we want to read, `output` is a Julia array (with the correct element
type and size because we queried that earlier), and `length` is the total
length of `output`.

Naturally I have to do an extra copy to pack the data into `output`, but it
works nicely enough for ints, floats, doubles, etc. However I haven't
figured out how to get this to work for strings (all of which potentially
have a different length).

So what is the best way to get an array of strings from C back into Julia?
I want Julia to take ownership of the memory. Do I need to query the length
of each string ahead of time?


Reply via email to