Archived
Best way to avoid deep copies when sending a large floating point sequence
I have a slice that maps to an std::vector<float>
. Although expected, I was hoping for there to be a way to avoid a deep copy when my program can only pass pointers. I need to use pointers because of exotic memory allocation requirements, aka page locked, etc.
At present I'm deep copying the pointed data into a vector, but I think something exists for strings (that maps to string_view
). I can't figure out how to apply this to a sequence of floating point data.
sequence<float> InteropBuffer; interface Interop { void sendData(InteropBuffer input); };
Comments
-
Hi Mikhail,
The simplest solution here is probably to use the
cpp::array
metadata, which will map yoursequence<float>
parameter to an array of floats (really a pair of pointers). See
https://doc.zeroc.com/pages/viewpage.action?pageId=16716050#C++MappingforSequences-ArrayMappingforSequenceParametersinC++ (Ice 3.6)https://doc.zeroc.com/pages/viewpage.action?pageId=18255292#C++11MappingforSequences-ArrayMappingforSequenceParametersinC++ (Ice 3.7 with C++11)
You could also use a "view type", but this would require more coding:
you'd map the
sequence<float>
sequence to your own C++ type with "view" semantics (meaning it does not own the float array memory): https://doc.zeroc.com/display/Ice36/The+cpp:type+and+cpp:view-type+Metadata+Directives#Thecpp:typeandcpp:view-typeMetadataDirectives-Avoidingcopieswithcpp:view-type (Ice 3.6). Let's call this custom typeFloatArrayView
.you'd tell Ice how to marshal and unmarshal this
FloatArrayView
through Stream Helpers: https://doc.zeroc.com/pages/viewpage.action?pageId=16716071 (Ice 3.6)
Best regards,
Bernard0