Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Can any body explain me below statement of function ?
Forum Updated to NodeBB v4.3 + New Features

Can any body explain me below statement of function ?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
30 Posts 4 Posters 8.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    i want to know the what is technical meaning of below statement

    sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));

    shall i need to free memory allocated to SqliteManagerBGSync() ?

    // in class header
    static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
    
    // in class defination
    SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
    {
    	std::map<int,SqliteManagerBGSync*>::iterator it;
    	int threadId = pthread_self();
    	DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId);
    
    	//sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty
    	//Return 1 If sqliteManagerMap is Empty
    	DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty());
    
    	if(sqliteManagerMap.empty())
    	{
    		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF");
    		if(pthread_mutex_init(&databaseLock, NULL) != 0)
    		{
    			DBGF_TRACE("databaseLock mutex init failed");
    
    		}
    		else
    		{
    			DBGF_TRACE("databaseLock mutex init Success");
    
    		}
    	}
    //	else
    //	{
    //		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else");
    //		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
    //		it = sqliteManagerMap.find(threadId);
    //		DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1");
    //		return it->second;
    //	}
    
    	it = sqliteManagerMap.find(threadId);
    	if(it == sqliteManagerMap.end())
    	{
    		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success");
    
    		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
    		DBGF_TRACE("AFCS:sqliteManagerMap insert called");
    
    		it = sqliteManagerMap.find(threadId);
    	}
    	DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2");
    
    	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max());
    	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current());
    
    	return it->second;
    }
    
    jsulmJ KroMignonK 2 Replies Last reply
    0
    • Q Qt embedded developer

      i want to know the what is technical meaning of below statement

      sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));

      shall i need to free memory allocated to SqliteManagerBGSync() ?

      // in class header
      static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
      
      // in class defination
      SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
      {
      	std::map<int,SqliteManagerBGSync*>::iterator it;
      	int threadId = pthread_self();
      	DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId);
      
      	//sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty
      	//Return 1 If sqliteManagerMap is Empty
      	DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty());
      
      	if(sqliteManagerMap.empty())
      	{
      		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF");
      		if(pthread_mutex_init(&databaseLock, NULL) != 0)
      		{
      			DBGF_TRACE("databaseLock mutex init failed");
      
      		}
      		else
      		{
      			DBGF_TRACE("databaseLock mutex init Success");
      
      		}
      	}
      //	else
      //	{
      //		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else");
      //		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
      //		it = sqliteManagerMap.find(threadId);
      //		DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1");
      //		return it->second;
      //	}
      
      	it = sqliteManagerMap.find(threadId);
      	if(it == sqliteManagerMap.end())
      	{
      		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success");
      
      		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
      		DBGF_TRACE("AFCS:sqliteManagerMap insert called");
      
      		it = sqliteManagerMap.find(threadId);
      	}
      	DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2");
      
      	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max());
      	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current());
      
      	return it->second;
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Qt-embedded-developer said in Can any body explain me below statement of function ?:

        sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));

        Well, here you create std::pair<int,SqliteManagerBGSync*> containing threadId and pointer to SqliteManagerBGSync instance. Then that pair is passed to sqliteManagerMap.insert(...).
        Yes, you have to delete SqliteManagerBGSync at some point when it is not needed anymore.

        Q 1 Reply Last reply
        1
        • Q Qt embedded developer

          i want to know the what is technical meaning of below statement

          sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));

          shall i need to free memory allocated to SqliteManagerBGSync() ?

          // in class header
          static SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
          
          // in class defination
          SqliteManagerBGSync* SqliteManagerBGSync::GetDBInstance()
          {
          	std::map<int,SqliteManagerBGSync*>::iterator it;
          	int threadId = pthread_self();
          	DBGF_TRACE("AFCS:SqliteManagerBGSync::thread Id :%d",threadId);
          
          	//sqliteManagerMap.empty() Return 0 If sqliteManagerMap is Not Empty
          	//Return 1 If sqliteManagerMap is Empty
          	DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty()=%d",sqliteManagerMap.empty());
          
          	if(sqliteManagerMap.empty())
          	{
          		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() IF");
          		if(pthread_mutex_init(&databaseLock, NULL) != 0)
          		{
          			DBGF_TRACE("databaseLock mutex init failed");
          
          		}
          		else
          		{
          			DBGF_TRACE("databaseLock mutex init Success");
          
          		}
          	}
          //	else
          //	{
          //		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::sqliteManagerMap.empty() Else");
          //		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
          //		it = sqliteManagerMap.find(threadId);
          //		DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 1");
          //		return it->second;
          //	}
          
          	it = sqliteManagerMap.find(threadId);
          	if(it == sqliteManagerMap.end())
          	{
          		DBGF_TRACE("AFCS:SqliteManagerBGSync::GetDBInstance()::threadId Find Success");
          
          		sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));
          		DBGF_TRACE("AFCS:sqliteManagerMap insert called");
          
          		it = sqliteManagerMap.find(threadId);
          	}
          	DBGF_TRACE("AFCS:SqliteManagerBGSync::sqliteManagerMap success return 2");
          
          	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_max() = %d",_heap_max());
          	DBGF_TRACE("SqliteManagerBGSync::GetDBInstance _heap_current() = %d",_heap_current());
          
          	return it->second;
          }
          
          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #4

          @Qt-embedded-developer said in Can any body explain me below statement of function ?:

          i want to know the what is technical meaning of below statement
          sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync>(threadId,new SqliteManagerBGSync()));
          shall i need to free memory allocated to SqliteManagerBGSync() ?

          I think the idea between this is to get access to DB connection which has been created for the current thread (as QSqlDatabase has to be used in the thread in which it has been created).

          But to answer to your question, yes you have to free used memory.
          The easiest way to do it, would be to use smart pointer, like QSharedPointer ==> use QSharedPointer<SqliteManagerBGSync> instead of SqliteManagerBGSync*.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          Q 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Qt-embedded-developer said in Can any body explain me below statement of function ?:

            sqliteManagerMap.insert(std::pair<int,SqliteManagerBGSync*>(threadId,new SqliteManagerBGSync()));

            Well, here you create std::pair<int,SqliteManagerBGSync*> containing threadId and pointer to SqliteManagerBGSync instance. Then that pair is passed to sqliteManagerMap.insert(...).
            Yes, you have to delete SqliteManagerBGSync at some point when it is not needed anymore.

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on last edited by Qt embedded developer
            #5

            @jsulm @KroMignon Can anybody explain me how to free this map and memory allocated to instance ?

            KroMignonK 1 Reply Last reply
            0
            • Q Qt embedded developer

              @jsulm @KroMignon Can anybody explain me how to free this map and memory allocated to instance ?

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #6

              @Qt-embedded-developer said in Can any body explain me below statement of function ?:

              Can you let me know how to free this map and memory allocated to instance ?

              As written before, there are 2 options:

              • use smart pointer, memory will be release when item is removed from map
              • call "manually" delete to free memory when item is removed from map.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Q 1 Reply Last reply
              1
              • KroMignonK KroMignon

                @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                Can you let me know how to free this map and memory allocated to instance ?

                As written before, there are 2 options:

                • use smart pointer, memory will be release when item is removed from map
                • call "manually" delete to free memory when item is removed from map.
                Q Offline
                Q Offline
                Qt embedded developer
                wrote on last edited by Qt embedded developer
                #7

                @KroMignon can you give example for my map. how to delete & deallocate memory to it ?

                jsulmJ 1 Reply Last reply
                0
                • Q Qt embedded developer

                  @KroMignon can you give example for my map. how to delete & deallocate memory to it ?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Qt-embedded-developer What map? sqliteManagerMap? If so than there is no need to delete it as it is not allocated on the heap, apparently. To delete SqliteManagerBGSync instance use "delete" keyword as usual in C++ or use shared pointer as @KroMignon already suggested two times...

                  Q 1 Reply Last reply
                  2
                  • jsulmJ jsulm

                    @Qt-embedded-developer What map? sqliteManagerMap? If so than there is no need to delete it as it is not allocated on the heap, apparently. To delete SqliteManagerBGSync instance use "delete" keyword as usual in C++ or use shared pointer as @KroMignon already suggested two times...

                    Q Offline
                    Q Offline
                    Qt embedded developer
                    wrote on last edited by Qt embedded developer
                    #9

                    @jsulm @KroMignon Hi i have access this instance based function in other class like below

                    app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase();

                    And actually it is complex such that i am unable to understand how to delete it ?

                    So i nee example to delete it.

                    i have attached the code for openDatabase()

                    int SqliteManagerBGSync::openDatabase()
                    {
                    	DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex locking");
                    
                    	if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0)
                    	{
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 1");
                    
                    		pthread_mutex_lock(&databaseLock);
                    	}
                    	DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Locked");
                    
                    
                    	if(handle != NULL){
                    		DBGF_TRACE("AFCS:SqliteManagerBGSync::Handle success");
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                    		return SUCCESS;
                    	}
                    
                    	int res = sqlite3_open(DB_PATH, &handle);
                    	DBGF_TRACE("AFCS:SqliteManagerBGSync::sqlite3 open = %d",res);
                    
                    
                    	DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::mutex lock called");
                    	if(res != SQLITE_OK)
                    	{
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocking");
                    		if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0)
                    		{
                    			DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 2");
                    			pthread_mutex_unlock(&databaseLock);
                    		}
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocked");
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                    	    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                    		ERROR_RETURN(-1);
                    	}else{
                    		DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::Sqlite ok");
                    
                    		if(sqlite3_exec(handle, "PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;", NULL, 0, NULL) == SQLITE_OK)
                    		{
                    			DBGF_TRACE(" SQLITE QUERY SUCCESS: PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;");
                    			DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                    		    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                    			return SUCCESS;
                    		}
                    		else
                    		{
                    			DBGF_TRACE(" SQLITE QUERY FAIL : PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;");
                    			DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                    		    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                    			ERROR_RETURN(0);
                    		}
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                    		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                    		return SUCCESS;
                    	}
                    
                    }
                    

                    below i shown other class's function where i used above function :

                    int CheckTotalErrorStep::FeatchTotalErrorCount()
                    {
                    	std::string strCurrentDate="0";
                    	strCurrentDate = boomer::utils::datetime::getCurrentDateTime("YYYY-MM-DD");
                    	DBGF_TRACE("AFCS:ReprintTicketStep::CheckNoOfTimesTryingToRePrintTicket()");
                    	char *errMsg;
                    	int result=0;
                    	std::string usr_query="";
                    	intTotalInsertedErrorLogCount = 0;
                    	if(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase() != SUCCESS)
                    	{
                    		ERROR_RETURN(0);
                    	}
                    	else
                    	{
                    		std::stringstream sql;
                    
                    		usr_query = "SELECT COUNT(INTERRORLOGID) FROM TBLERRORLOGS WHERE date(DTEERRORDATETIME) = '" + strCurrentDate + "';";
                    
                    		DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() : :usr_query=%s",usr_query);
                    		result = sqlite3_exec(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle, usr_query.c_str(), &GetTotalErrorCount, 0, &errMsg);
                    		DBGF_TRACE("AFCS:CheckTotalErrorStep::FeatchTotalErrorCount():result=%d",result);
                    		if(result == SQLITE_OK)
                    		{
                    			app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase();
                    			return SQLITE_OK;
                    		}
                    		else
                    		{
                    			DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() :Error=%s",sqlite3_errmsg(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle));
                    			app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase();
                    			return SQLITE_ERROR;
                    		}
                    	}
                    	return result;
                    }
                    

                    I am not using the QT. i am only using c++. i want to know shall i need to use shared pointer in map ?

                    can anybody give example to deallocate memory for above singleton based class ?

                    KroMignonK 1 Reply Last reply
                    0
                    • Q Qt embedded developer

                      @jsulm @KroMignon Hi i have access this instance based function in other class like below

                      app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase();

                      And actually it is complex such that i am unable to understand how to delete it ?

                      So i nee example to delete it.

                      i have attached the code for openDatabase()

                      int SqliteManagerBGSync::openDatabase()
                      {
                      	DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex locking");
                      
                      	if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0)
                      	{
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 1");
                      
                      		pthread_mutex_lock(&databaseLock);
                      	}
                      	DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Locked");
                      
                      
                      	if(handle != NULL){
                      		DBGF_TRACE("AFCS:SqliteManagerBGSync::Handle success");
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                      		return SUCCESS;
                      	}
                      
                      	int res = sqlite3_open(DB_PATH, &handle);
                      	DBGF_TRACE("AFCS:SqliteManagerBGSync::sqlite3 open = %d",res);
                      
                      
                      	DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::mutex lock called");
                      	if(res != SQLITE_OK)
                      	{
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocking");
                      		if(app::Header::AFCSTicket::GetAFCSTicketInstance()->getDBClosed()!=0)
                      		{
                      			DBGF_TRACE("SqliteManagerBGSync::openDatabase():: If 2");
                      			pthread_mutex_unlock(&databaseLock);
                      		}
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase::Mutex Unlocked");
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                      	    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                      		ERROR_RETURN(-1);
                      	}else{
                      		DBGF_TRACE("AFCS:SqliteManagerBGSync::openDatabase::Sqlite ok");
                      
                      		if(sqlite3_exec(handle, "PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;", NULL, 0, NULL) == SQLITE_OK)
                      		{
                      			DBGF_TRACE(" SQLITE QUERY SUCCESS: PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;");
                      			DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                      		    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                      			return SUCCESS;
                      		}
                      		else
                      		{
                      			DBGF_TRACE(" SQLITE QUERY FAIL : PRAGMA journal_mode = WAL;PRAGMA  cache_size = 100000;");
                      			DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                      		    DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                      			ERROR_RETURN(0);
                      		}
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_max() = %d",_heap_max());
                      		DBGF_TRACE("SqliteManagerBGSync::openDatabase() _heap_current() = %d",_heap_current());
                      		return SUCCESS;
                      	}
                      
                      }
                      

                      below i shown other class's function where i used above function :

                      int CheckTotalErrorStep::FeatchTotalErrorCount()
                      {
                      	std::string strCurrentDate="0";
                      	strCurrentDate = boomer::utils::datetime::getCurrentDateTime("YYYY-MM-DD");
                      	DBGF_TRACE("AFCS:ReprintTicketStep::CheckNoOfTimesTryingToRePrintTicket()");
                      	char *errMsg;
                      	int result=0;
                      	std::string usr_query="";
                      	intTotalInsertedErrorLogCount = 0;
                      	if(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->openDatabase() != SUCCESS)
                      	{
                      		ERROR_RETURN(0);
                      	}
                      	else
                      	{
                      		std::stringstream sql;
                      
                      		usr_query = "SELECT COUNT(INTERRORLOGID) FROM TBLERRORLOGS WHERE date(DTEERRORDATETIME) = '" + strCurrentDate + "';";
                      
                      		DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() : :usr_query=%s",usr_query);
                      		result = sqlite3_exec(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle, usr_query.c_str(), &GetTotalErrorCount, 0, &errMsg);
                      		DBGF_TRACE("AFCS:CheckTotalErrorStep::FeatchTotalErrorCount():result=%d",result);
                      		if(result == SQLITE_OK)
                      		{
                      			app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase();
                      			return SQLITE_OK;
                      		}
                      		else
                      		{
                      			DBGF_TRACE("CheckTotalErrorStep::FeatchTotalErrorCount() :Error=%s",sqlite3_errmsg(app::dbmanager::SqliteManagerBGSync::GetDBInstance()->handle));
                      			app::dbmanager::SqliteManagerBGSync::GetDBInstance()->closeDatabase();
                      			return SQLITE_ERROR;
                      		}
                      	}
                      	return result;
                      }
                      

                      I am not using the QT. i am only using c++. i want to know shall i need to use shared pointer in map ?

                      can anybody give example to deallocate memory for above singleton based class ?

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #10

                      @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                      And actually it is complex such that i am unable to understand how to delete it ?
                      So i nee example to delete it.

                      I don't understand what looks complicated to you.
                      You have to delete the instance when you remove it from map.

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      Q 1 Reply Last reply
                      1
                      • KroMignonK KroMignon

                        @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                        And actually it is complex such that i am unable to understand how to delete it ?
                        So i nee example to delete it.

                        I don't understand what looks complicated to you.
                        You have to delete the instance when you remove it from map.

                        Q Offline
                        Q Offline
                        Qt embedded developer
                        wrote on last edited by Qt embedded developer
                        #11

                        @KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.

                        as you can see that how i accessed GetAFCSTicketInstance() in other class.

                        so where i need to put "delete SqliteManagerBGSync" ?

                        jsulmJ KroMignonK 2 Replies Last reply
                        0
                        • Q Qt embedded developer

                          @KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.

                          as you can see that how i accessed GetAFCSTicketInstance() in other class.

                          so where i need to put "delete SqliteManagerBGSync" ?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                          so where i need to put "delete SqliteManagerBGSync" ?

                          You could do it in the destructor of the class holding sqliteManagerMap member.

                          Q 1 Reply Last reply
                          1
                          • Q Qt embedded developer

                            @KroMignon actually i have seen that already completely developed project never removed it. and never deleted it.

                            as you can see that how i accessed GetAFCSTicketInstance() in other class.

                            so where i need to put "delete SqliteManagerBGSync" ?

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by
                            #13

                            @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                            actually i have seen that already completely developed project never removed it. and never deleted it.
                            as you can see that how i accessed GetAFCSTicketInstance() in other class.
                            so where i need to put "delete SqliteManagerBGSync" ?

                            As far as I can see, app::dbmanager::SqliteManagerBGSync::GetDBInstance() seems to be a static method, so I guess the map is also an static member of class app::dbmanager::SqliteManagerBGSync.
                            To be totally clean, I would add a static method cleanup() to this class to clear properly the map:

                            for (const auto& kv : sqliteManagerMap) {
                                delete kv.second;
                            }
                            sqliteManagerMap.clear();
                            

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            Q 1 Reply Last reply
                            1
                            • jsulmJ jsulm

                              @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                              so where i need to put "delete SqliteManagerBGSync" ?

                              You could do it in the destructor of the class holding sqliteManagerMap member.

                              Q Offline
                              Q Offline
                              Qt embedded developer
                              wrote on last edited by
                              #14
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • KroMignonK KroMignon

                                @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                actually i have seen that already completely developed project never removed it. and never deleted it.
                                as you can see that how i accessed GetAFCSTicketInstance() in other class.
                                so where i need to put "delete SqliteManagerBGSync" ?

                                As far as I can see, app::dbmanager::SqliteManagerBGSync::GetDBInstance() seems to be a static method, so I guess the map is also an static member of class app::dbmanager::SqliteManagerBGSync.
                                To be totally clean, I would add a static method cleanup() to this class to clear properly the map:

                                for (const auto& kv : sqliteManagerMap) {
                                    delete kv.second;
                                }
                                sqliteManagerMap.clear();
                                
                                Q Offline
                                Q Offline
                                Qt embedded developer
                                wrote on last edited by
                                #15

                                @KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use

                                delete SqliteManagerBGSync() ; in cleanup() memthod.

                                May be i am wrong. if it is then please correct me .

                                jsulmJ KroMignonK 2 Replies Last reply
                                0
                                • Q Qt embedded developer

                                  @KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use

                                  delete SqliteManagerBGSync() ; in cleanup() memthod.

                                  May be i am wrong. if it is then please correct me .

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                  delete SqliteManagerBGSync() ;

                                  Does not make sense and is not valid C++ - you are trying to delete a new stack allocated SqliteManagerBGSync instance...

                                  Q 1 Reply Last reply
                                  1
                                  • Q Qt embedded developer

                                    @KroMignon as you can see from my function that i have taken the local map in function.so on scope get completed this map also get deleted. But there is i think SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use

                                    delete SqliteManagerBGSync() ; in cleanup() memthod.

                                    May be i am wrong. if it is then please correct me .

                                    KroMignonK Offline
                                    KroMignonK Offline
                                    KroMignon
                                    wrote on last edited by KroMignon
                                    #17

                                    @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                    SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
                                    delete SqliteManagerBGSync() ; in cleanup() memthod.
                                    May be i am wrong. if it is then please correct me .

                                    I don't want to hurt, just to know how to help you, but what are your programming skills?
                                    Do you know what are static methods or classes?
                                    According to you code extract, SqliteManagerBGSync is a class.
                                    I guess method GetDBInstance() is declared in header as follow:

                                    class SqliteManagerBGSync
                                    {
                                    public:
                                        static SqliteManagerBGSync* GetDBInstance();
                                    };
                                    

                                    Correct or wrong?

                                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                    Q 1 Reply Last reply
                                    1
                                    • jsulmJ jsulm

                                      @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                      delete SqliteManagerBGSync() ;

                                      Does not make sense and is not valid C++ - you are trying to delete a new stack allocated SqliteManagerBGSync instance...

                                      Q Offline
                                      Q Offline
                                      Qt embedded developer
                                      wrote on last edited by
                                      #18

                                      @jsulm So then just let me know this local map allocated the dynamic memory to class when and how to delete it with example. still i am misinterpret it then let me know.

                                      1 Reply Last reply
                                      0
                                      • KroMignonK KroMignon

                                        @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                        SqliteManagerBGSync() is global which get allocated to memory so i think shall i need to use
                                        delete SqliteManagerBGSync() ; in cleanup() memthod.
                                        May be i am wrong. if it is then please correct me .

                                        I don't want to hurt, just to know how to help you, but what are your programming skills?
                                        Do you know what are static methods or classes?
                                        According to you code extract, SqliteManagerBGSync is a class.
                                        I guess method GetDBInstance() is declared in header as follow:

                                        class SqliteManagerBGSync
                                        {
                                        public:
                                            static SqliteManagerBGSync* GetDBInstance();
                                        };
                                        

                                        Correct or wrong?

                                        Q Offline
                                        Q Offline
                                        Qt embedded developer
                                        wrote on last edited by
                                        #19

                                        @KroMignon yes it is static. thanks. just let me help me how to make this code proper.

                                        Because i have see that my application is get restarted due too much heap utilization.

                                        and i think this above code is reason for that.

                                        KroMignonK 1 Reply Last reply
                                        0
                                        • Q Qt embedded developer

                                          @KroMignon yes it is static. thanks. just let me help me how to make this code proper.

                                          Because i have see that my application is get restarted due too much heap utilization.

                                          and i think this above code is reason for that.

                                          KroMignonK Offline
                                          KroMignonK Offline
                                          KroMignon
                                          wrote on last edited by KroMignon
                                          #20

                                          @Qt-embedded-developer said in Can any body explain me below statement of function ?:

                                          yes it is static. thanks. just let me help me how to make this code proper.
                                          Because i have see that my application is get restarted due too much heap utilization.
                                          and i think this above code is reason for that.

                                          This code don't look bad to me and I don't think it is the place where heap memory is consuming.
                                          As written before, it will only ensure that you are using the right SqliteManagerBGSync for the current thread and create a new SqliteManagerBGSync if there is no one already created for current thread.

                                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                          Q 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved