passing a structure pointer cross threads with global vector
I have a vector of structure pointers.
The vector is in global space so I can access it from worker threads.
I have a couple of access functions like Pop, Push, and GetSize that do locking on any access to the vector.
In Thread One:
I create a structure pointer;
mystructure* pmystructure = new mystructure;
Constructor is called!!
load data items;
pmystructure->value1="hello";
etc...
Push(pmystructure)
Places it in the vector.
In Thread Two:
mystructure * pstruct=NULL;
return a *mystructure type with Pop().
pstruct=Pop();
Then I use the values in that structure.
cout<<(LPCSTR)pstruct->value1<<endl;
My issue is when I try to delete the pstruct.
When i have the following;
delete pstruct;
pstruct=NULL;
The destructor is never called and my heap seems to keep all the memory allocated.
How do I call the destructor to the structure and there by the smart pointers will call their destructors and free the heap allocation for the struct and its members and allow it back to the OS?
Bookmarks