Table of contents
1.
Introduction
2.
Memory Management Class- CComGITPtr
2.1.
Syntax
3.
Members of CComGITPtr
3.1.
Public Constructor and Destructor
3.1.1.
CComGITPtr::CComGITPtr
3.1.2.
CComGITPtr::~CComGITPtr
3.2.
Public Data Members
3.3.
Public Methods
3.3.1.
CComGITPtr::Attach
3.3.2.
CComGITPtr::CopyTo
3.3.3.
CComGITPtr::Detach
3.3.4.
CComGITPtr::GetCookie
3.3.5.
CComGITPtr::Revoke
3.4.
Public Operators
3.4.1.
CComGITPtr::operator DWORD
3.4.2.
CComGITPtr::operator =
4.
Frequently Asked Questions
4.1.
Can I use the Global Interface Table in every Windows system?
4.2.
What is Component Object Model(COM)?
4.3.
What do you mean by DWORD?
5.
Conclusion
Last Updated: Mar 27, 2024
Hard

Memory Management Class- CComGITPtr

Author Nidhi Kumari
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Have you ever experienced an application crash, an app hanged, stopped services, a timeout issue or a bad performance problem in your system? The most frequent cause of all of these issues is "MEMORY LEAKS." Even a very minor memory leak can eventually cause software or system crashes. Memory management is one of the best ways to solve memory-related problems.

 In this article, we will learn about the memory management class- CComGITPtr.

Memory Management Class- CComGITPtr

Memory Management Class- CComGITPtr

The CComGITPtr is a memory management class in Active Template Library. The Active Template Library is a collection of Microsoft C++ template classes (programme routines) that are specially made to make it easier to code and develop for the Component Object Model (COM) and ActiveX.

The CComGITPtr class provides methods for handling interface pointers and the global interface table (GIT). 

An interface pointer is a pointer(reference)  to an object instance. The object points to the implementation of each interface method. It takes more effort to pass interfaces across several threads.

You can access the COM interface built in any thread, anywhere, thanks to the global interface table (GIT). GIT is a COM object and is used to implement the iglobalinterfacetable interface.

The required header file: atlbase.h 

Syntax

The syntax of the CComGITPtr class is as follows:

template <class T>
class CComGITPtr


Parameter

Here, T is a type of interface pointer stored in GIT. 

Members of CComGITPtr

The various members of CComGITPtr class are as follows:

  • Constructors.
     
  • Destructors.
     
  • Data Members.
     
  • Methods.
     
  • Operators.
     

Public Constructor and Destructor

  • CComGITPtr::CComGITPtr is the public constructor that is used to initialize the new object of the class with the option of using an already existing one.
    The move constructor is the one using rv. After the data has been transferred from the source(rv) it is cleared.
     
  • CComGITPtr::~CComGITPtr is the public destructor that is used to destroy the object.
     

CComGITPtr::CComGITPtr

The syntax of the public constructor is as follows:

CComGITPtr() throw();
CComGITPtr(T* p);
CComGITPtr(const CComGITPtr& git);
explicit CComGITPtr(DWORD dwCookie) throw();
CComGITPtr(CComGITPtr&& rv);

 

Parameters

  • p: A pointer to an interface that will be kept in the global interface table (GIT).
     
  • Git is a reference to a CComGITPtr object that already exists.
     
  • dwCookie: An interface pointer identification cookie.
     
  • rv: The CComGITPtr object from which to move data.

 

CComGITPtr::~CComGITPtr

Using CComGITPtr::Revoke, the interface is removed from the GIT.

The syntax of the public destructor is as follows:

~CComGITPtr() throw();

Public Data Members

CComGITPtr::m_dwCookie is a cookie used as a data member of the CComGITPtr class. It is used to identify the location of the interface and the interface itself.

The syntax of the data member is as follows:

DWORD m_dwCookie;

Public Methods

  • CComGITPtr::Attach method is used to add the interface pointer to the GIT.
     
  • CComGITPtr::CopyTo method is used to copy the interface pointer from GIT into a specified pointer.
     
  • CComGITPtr::Detach method is used to separate the interface from the CComGITPtr object.
     
  • CComGITPtr::GetCookie method is used to retrieve the cookie from the CComGITPtr object.
     
  • CComGITPtr::Revoke method deletes the interface from the global interface table.

 

CComGITPtr::Attach

The syntax for this method is as follows:

HRESULT Attach(T* p) throw();
HRESULT Attach(DWORD dwCookie) throw();

 

Parameters

  • p: A pointer to an interface that will be kept in the global interface table (GIT).
     
  • dwCookie: An interface pointer identification cookie.

 

Return Value

Success: S_OK

Failure: HRESULT (error)

CComGITPtr::CopyTo

The passed pointer receives a copy of the GIT interface. When it is no longer needed, the caller must release the pointer.

The syntax of this method is as follows:

HRESULT CopyTo(T** pp) const throw();

 

Parameters

pp: The pointer that will be given access to the interface.

 

Return Value

Success: S_OK

Failure: HRESULT (error)

 

CComGITPtr::Detach

To separate the interface from the CComGITPtr object, call this method.

The syntax of this method is as follows:

DWORD Detach() throw();

 

Return Value

The cookie is returned from the CComGITPtr object in the return value.

 

CComGITPtr::GetCookie

To retrieve the cookie from the CComGITPtr object, call this method.

The syntax of this method is as follows:

DWORD GetCookie() const;

 

Return Value

The cookie to identify an interface.

 

CComGITPtr::Revoke

Use this method to delete the current interface from the global interface table.

The syntax of this method is as follows:

HRESULT Revoke() throw();

 

Return Value

Success: S_OK

Failure: HRESULT (error)

Public Operators

  • CComGITPtr::operator DWORD operator gives the CComGITPtr object's related cookie back.
     
  • CComGITPtr::operator = is the assignment operator.
     

CComGITPtr::operator DWORD

The received cookie is used to identify an interface pointer.

The prototype for this operator is as follows:

operator DWORD() const;

 

CComGITPtr::operator =

It assigns a CComGITPtr object. You can derive a new value from another existing object or a reference to a global interface table.

The prototype for this operator is as follows:

CComGITPtr& operator= (T* p);
CComGITPtr& operator= (const CComGITPtr& git);
CComGITPtr& operator= (DWORD dwCookie);
CComGITPtr& operator= (CComGITPtr&& rv);

 

Parameters

  • p: A pointer to an interface that will be kept in the global interface table (GIT).
     
  • Git is a reference to a CComGITPtr object that already exists.
     
  • dwCookie: An interface pointer identification cookie.
     
  • rv: The CComGITPtr object from which to move data.

 

Return Value

The modified CComGITPtr object is returned.
You can also read about the memory hierarchy.

Check out most important Git Interview Questions here.

Frequently Asked Questions

Can I use the Global Interface Table in every Windows system?

No! The Global Interface Table is not supported in all Windows systems. Only Windows 95 with DCOM version 1.1, Windows 98, Windows NT 4.0 with Service Pack 3 and later, and Windows 2000 support the global interface table feature.

What is Component Object Model(COM)?

The Component Object Model (COM) software architecture can create applications from binary software components. The supporting architecture known as COM is the building block for higher-level software services. COM is a platform-independent system. It is a simple specification method.

What do you mean by DWORD?

The data type description for Microsoft Windows is called a "dword," which is short for "double word." A dword is a 32-bit unsigned data unit as defined in the file windows.h. It may include an integer value between 0 and 4,294,967,295.

Conclusion

We have discussed the memory management class- CComGITPtr. The CComGITPtr is a memory management class in Active Template Library. The CComGITPtr class provides methods for handling interface pointers and the global interface table (GIT). 

We hope this blog has helped you. We recommend you visit our articles on different topics of ATL, such as

🔥 ATL module classes.

🔥 Memory management class-CComHeap and CComHeapPtr.

🔥 Memory management class-CAutoPtr.

If you liked our article, do upvote our article and help other ninjas grow.  You can refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more!

Head over to our practice platform Coding Ninjas Studio to practise top problems, attempt mock tests, read interview experiences and interview bundles, follow guided paths for placement preparations, and much more!!

Happy Reading!!

Live masterclass