CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009

    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;

    Places it in the vector.

    In Thread Two:
    mystructure * pstruct=NULL;
    return a *mystructure type with Pop().

    Then I use the values in that structure.

    My issue is when I try to delete the pstruct.
    When i have the following;

    delete pstruct;

    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,

  2. #2
    Join Date
    Nov 2003

    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?


  3. #3
    Join Date
    Feb 2002

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.