generated peer destructor implementation

  • Zoltan Filyo

    Zoltan Filyo - 2005-10-11


    When the peer class allocates resources by overridden initialize() function,
    then it must release the allocated resources too. The generated peer destructor is the right place for do that. But the peer generator generates an empty destructor for the peer in "*_peer.cpp" source file.

    To perform the release process in the current status of the jace I should write an embedded friend class with same destructor code as the original peer would does.

    Example of contents of "sample_peer.h":


            // Variable to store additional resource. It will be initialized by
            // initialize()
            HANDLE m_resourceHandle;

            // Embedded class that manages additional resources.
            class EmbeddedDestructor {
                    Sample* m_samplePtr;
                    void init(Sample* p_samplePtr) {
                        m_samplePtr = p_samplePtr;
                    ~EmbeddedDestructor() {
                        // Free allocated resource
                        if (NULL != m_samplePtr)

        friend class EmbeddedDestructor;
        EmbeddedDestructor m_deallocator;       

    I dislike this hack above, however the advantage is that it does not touch jace code.
    The second and third solution (below) requires modification of the jace code.
    The second solution is an additional program switch that controls the destructor
    generation in the peerGenerator program.
    I prefer the third solution: The peer destructor does not generated by the peerGenerator in the class body but in the header. In this case the linker will not produce executable if the peer implementor forgets to write the peer destructor, but it gives more freedom for him/her.
    What do you think about it?

    Fily Zoltn

    • Zoltan Filyo

      Zoltan Filyo - 2005-10-14

      I am very sorry. I found the destroy() now. Please forget it.
      Fily Zoltn


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks