vector allocation confusion
I have a Tree class of the following type
class Tree{
private:
Node *root; // trie root node
unordered_map<int, vector<Node*> > *index;
unsigned long long size;
int count;
public:
................
};
I am having a vector of the following type
vector<Tree> vect;
With the above declaration I am encountering a segmentation fault when a number of nodes are added to each of the Tree.
But the same works perfectly when I use the following declaration
vector<Tree*> vect;
and allocate each Tree* pointer explicitly on the heap using new
The segmentation fault seems as if it occurs because of excessive memory utilization of the stack.
And from a previous question in stack overflow I was told that in the first declaration each Tree object will be allocated on the heap.
Any thoughts on this?
With your little code, I guess you have problems in your copy constructor and operator=. Each time you add new item in your vector, there is a copy invocation. In the case of vector of pointers, there is no problems, but with your class, you will have problems with your pointer and map. Implement these methods correctly and try again.
链接地址: http://www.djcxy.com/p/82982.html上一篇: HTML5 Speech Synthesis API语音/语言支持
下一篇: 矢量分配混乱