// Bridging C header file:
struct Cxx_Data {
double value, rate;
... /* a bunch more doubles */
};
double some_c_function(CxxData const* data);
// Swift code:
public struct RT {
public func analyze() -> Double {
// I would like to pass the address of actual_data here.
// And I would *really* like to not gratuitously copy actual_data either!
some_c_function( ? )
}
var actual_data: Cxx_Data
}
-
If I was willing to make analyze() mutating, I could write
some_c_function(&actual_data)
which is quite fast, but at the cost of marking this function mutating, when it's not.
(And which forces me to make instances of RT be var when the could be let.) -
I could use withUnsafePointer { }, but this (as far as I can tell) will make a copy
of actual_data. I can't use the inout version of withUnsafePointer without making
the function mutating.
Is there no way to obtain a lightweight pointer to actual_data, given that
my C method specifically says it takes a const pointer?