Notifications
Clear all
[Closed] fetch array of node pointers sdk
Mar 20, 2015 6:25 pm
I know array have to have a predefined count when you declare them. So how would I get an amount of objects pointers to use them later? Like in the code below.
int N_Count = ip->GetSelNodeCount();
INode *MyNodes[N_Count];
for (int i = 0; i < ip->GetSelNodeCount(); i++){
MyNodes[i] = ip->GetSelNode(i);
}
or
int N_Count = ip->GetSelNodeCount();
INode *MyNodes;
MyNodes = new INode[N_Count];
for (int i = 0; i < ip->GetSelNodeCount(); i++){
MyNodes[i] = ip->GetSelNode(i);
}
2 Replies
Mar 20, 2015 6:25 pm
IMHO in that case it’s better to use classes that support dynamic array sizes like INodeTab, MaxSDK::Array and stl vector (for internal plugin stuff) rather than raw arrays.
INodeTab
INodeTab nodes;
for (auto i = 0; i < ip->GetSelNodeCount(); ++i)
nodes.AppendNode(ip->GetSelNode(i));
MaxSDK::Array
MaxSDK::Array<INode*> nodes;
for (auto i = 0; i < ip->GetSelNodeCount(); ++i)
nodes.append(ip->GetSelNode(i));
stl vector
std::vector<INode*> nodes;
for (auto i = 0; i < ip->GetSelNodeCount(); ++i)
nodes.push_back(ip->GetSelNode(i));
You can also init all these classes with a fixed size (see documentation) so you can do nodes[i] = ip->GetSelNode(i);. That way no reallocation of memory is needed when nodes are appended.