-
June 29th, 2012, 12:10 PM
#1
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.
struct mystructure
{
_bstr_t value1;
_bstr_t value2;
int active;
mystructure(void){printf("\nConstructer Called!\n");}
~mystructure(void){printf("\nDestructer Called!\n");}
};
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?
Hope I am clear on my intent here.
All help is respected.
Thank you,
MGP
-
June 29th, 2012, 01:34 PM
#2
Re: passing a structure pointer cross threads with global vector
Can you post a simple console application that we can compile and reproduce the issue?
gg
-
June 29th, 2012, 03:28 PM
#3
Re: passing a structure pointer cross threads with global vector
It looks like you're pushing/popping "new'd" objects, but never deleting all the objects in the global container.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|