• Create Account

### #ActualKhatharr

Posted 09 November 2012 - 12:47 AM

Thanks Khatharr.

Take the example of a very simple class:

class Node
{
Node* childNode;
std::vector<float>* vertices; // not safe to use vertices[i] or vertices.size() across dll boundary
}


The vector is always problematic, even if I just want to read values out of it.

But if I duplicate the needed data from the vector as POD, I can use it, like in this example:
class NodePOD
{
NodePOD* childNode; // ok to use across dll boundary
float* verticePointer; // ok to use across dll boundary
unsigned int verticeCount; // ok to use across dll boundary
std::vector<float>* vertices; // not safe to use across dll boundary
}

I don't really see what you're getting at. A vector is definitely not POD. You can't export the vector since you don't know if the other side can use or interpret it. Anything that's not POD has to be interfaced at public module boundaries. There's no way around it - it's the cost of portability.

That being said, it doesn't have to be heavy at all. You can store an iterator in the class to allow iteration and make a couple functions to manage that pretty easily.

[source lang="cpp"]export float* getNextFloat(Node* sourceNode) { return ++(sourceNode->iterator);}export void rewind(Node* sourceNode) { sourceNode->iterator = sourceNode->vertices.begin();}export float* getFloatByIndex(Node* sourceNode, int index) { return sourceNode->vertices[index];}[/source]

If it's not fast enough for traversal then I guess you could just restructure the class. Do you really need a vector there? Can it not be an array?

### #1Khatharr

Posted 09 November 2012 - 12:41 AM

Thanks Khatharr.

Take the example of a very simple class:

class Node
{
Node* childNode;
std::vector<float>* vertices; // not safe to use vertices[i] or vertices.size() across dll boundary
}


The vector is always problematic, even if I just want to read values out of it.

But if I duplicate the needed data from the vector as POD, I can use it, like in this example:
class NodePOD
{
NodePOD* childNode; // ok to use across dll boundary
float* verticePointer; // ok to use across dll boundary
unsigned int verticeCount; // ok to use across dll boundary
std::vector<float>* vertices; // not safe to use across dll boundary
}

I don't really see what you're getting at. A vector is definitely not POD. You can't export the vector since you don't know if the other side can use or interpret it. Anything that's not POD has to be interfaced at public module boundaries. There's no way around it - it's the cost of portability.

That being said, it doesn't have to be heavy at all. You can store an iterator in the class to allow iteration and make a couple functions to manage that pretty easily.

[source lang="cpp"]export float* getNextFloat(Node* sourceNode) { return ++(sourceNode->iterator);}export void rewind(Node* sourceNode) { sourceNode->iterator = sourceNode->vertices.begin();}export float* getFloatByIndex(Node* sourceNode, int index) { return sourceNode->vertices[index];}[/source]

PARTNERS