Providing std :: vector along a dll border is best practice for compiler independence

Providing STL containers along DLL boundaries is not a good idea and is not possible at all (see this answer for what and this on exposing std :: list along a dll border). I need to be able to transfer data between DLLs and EXEs compiled with different (VC08 / VC10 +) compilers; this Q only applies to that anyway.

What is the best way to expose them? Vectors are slightly different from lists in that memory is guaranteed to be continuous, so if I only need a constant doubling vector, can I just point in the start and end pointers to the block for the function in the dll? A DLL should also return some structure, like an array of vectors.

I wondered about the structure containing the start and end pointers:

template <typename T>
struct vecWrapper<T> {
    T*  begin;
    T*  end;
}

// in the dll
int func(vecWrapper<double> numbers);

Would that be reasonable? Presumably, no matter what returns from the function, you need a destructor (from the dll side), which destroys what it points to.

+5
source share
1 answer

. , , , , ( , ). , , .

, . std::vector , , ; , DLL, . , , , . STL , , , DLL.

+3

All Articles