Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:00+00:00 2026-05-26T00:38:00+00:00

I’m having trouble with the getFirst() functions , they’re supposed to return the first

  • 0

I’m having trouble with the getFirst() functions , they’re supposed to return the first element of the deque / vector but instead they return fixed values like 45 or 69!

For example: I Add(0xFB) … then try to printf(“%d”,p_MsgQueue->getFirst())
Output: 69 ????

MessageQueue.h

/*
 * Copyright (C) 2011 - 2012 Project Avalance
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef MESSAGEQUEUE_H
#define MESSAGEQUEUE_H

#define MQ_USE_DEQUE

#ifdef MQ_USE_VECTOR
#include <vector>
/* THIS VECTOR WILL BE USED BY MESSAGE_QUEUE TO STORE THE-TO BE PROCCESSED MESSAGES (SLASH) SIGNALS.*/
typedef std::vector<int> MESSAGE_LIST; // SHARED OBJECT .. MUST LOCK!

/* THIS CLASS WILL HANDLE THE MESSAGE LIST.*/
class MESSAGE_QUEUE {
public:
    MESSAGE_LIST * m_pList; // Pointer to our list, it's better to leave MESSAGE_LIST outside this class.
    MESSAGE_QUEUE(MESSAGE_LIST* pList){ m_pList = pList; } // POINTER TO OUR LIST HANDLER = POINTER TO THE LIST CREATED BY THE CALLING SCOPE MESSAGE_QUEUE (&AddressOfList)
    ~MESSAGE_QUEUE(){ } // Destructor , this will destroy m_pList when the class gets out of scope (todo)
    /* This class will be shared between threads that means any attempt to access it MUST be inside a critical section. */
    void Add( int messageCode ){ if(m_pList && messageCode!=0xFF)m_pList->push_back(messageCode);  } // Adding a message; Added check if input is 0xFF.
    int getLast( ){ if(m_pList){ return m_pList->back(); } return -1; } // MUST BE IN THE CODE : if(m_pList->size() == 0){ add(0xFF); } -- 0xFF CODE IS RESERVED! DO - NOT - USE
    void removeLast( ){ if(m_pList && m_pList->size() > 0){ m_pList->erase(m_pList->end()-1,m_pList->end()); } } // Deleting the last message , idk about iters+1 efficiency, there might be other ways to do it like advance(const_iterator,int)
    void removeFirst( ){ if(m_pList && m_pList->size() > 0){ m_pList->erase(m_pList->begin()); } }
    int getFirst( ){ if(m_pList){ return m_pList->front(); } return -1; }
};
#endif

#ifdef MQ_USE_DEQUE
#include <deque>
/* THIS VECTOR WILL BE USED BY MESSAGE_QUEUE TO STORE THE-TO BE PROCCESSED MESSAGES (SLASH) SIGNALS.*/
typedef std::deque<int> MESSAGE_LIST; // SHARED OBJECT .. MUST LOCK!

/* THIS CLASS WILL HANDLE THE MESSAGE LIST.*/
class MESSAGE_QUEUE {
public:
    MESSAGE_LIST * m_pList; // Pointer to our list, it's better to leave MESSAGE_LIST outside this class.
    MESSAGE_QUEUE(MESSAGE_LIST* pList){ m_pList = pList; } // POINTER TO OUR LIST HANDLER = POINTER TO THE LIST CREATED BY THE CALLING SCOPE MESSAGE_QUEUE (&AddressOfList)
    ~MESSAGE_QUEUE(){ } // Destructor , this will destroy m_pList when the class gets out of scope (todo)
    /* This class will be shared between threads that means any attempt to access it MUST be inside a critical section. */
    void Add( int messageCode ){ if(m_pList && messageCode!=0xFF)m_pList->push_back(messageCode);  } // Adding a message; Added check if input is 0xFF.
    int getLast( ){ if(m_pList){ return m_pList->back(); } return -1;} // MUST BE IN THE CODE : if(m_pList->size() == 0){ add(0xFF); } -- 0xFF CODE IS RESERVED! DO - NOT - USE
    void removeLast( ){ if(m_pList && m_pList->size() > 0){ m_pList->erase(m_pList->end()-1,m_pList->end()); } } // Deleting the last message , idk about iters+1 efficiency, there might be other ways to do it like advance(const_iterator,int)
    void removeFirst( ){ if(m_pList && m_pList->size() > 0){ m_pList->erase(m_pList->begin()); } }
    int getFirst( ){ if(m_pList){ return m_pList->front(); } return -1;}
};
#endif

#endif

Somewhere in Command.h

            ArgParser arg;
            int value = arg.GetHexArgs(_input,strlen("message -add 0x"));
            if(value == -1)CLog->out("\n Bad Arguement!");
            if(value != -1)CLog->out("\n 0x%X",value);
            LockSection Lc(Cs,errHandler);
            msgQueue->Add(value);
            printf(" %d ",msgQueue->getFirst());
            Lc.ForceCSectionLeave();

Main.cpp

LockSection lc(&crt,&err);
CLog->out(" [ Adding message = 0x45 ] Action : None \n");
g_msgQueue.Add(0x45);
CLog->out(" [ Adding message = 0xFD ] Action : Stalling Backgrounder Thread...\n");
g_msgQueue.Add(0xFD);
lc.ForceCSectionLeave();

/* Initialize Manager/Threads */
Backgrounder backgrounder;
if(backgrounder.Begin(&g_msgQueue,&crt,&err) == -1){ CLog->out(" - Initializing Backgrounder Sevice (backgrounder)  ... Failed!\n [Warning]! An error occured while initializing Backgrounder Sevice (backgrounder)."); }

CommandManager Cmd_Mgr;
if(Cmd_Mgr.Begin(&g_msgQueue,&crt,&err) == -1){ CLog->out(" - Initializing Command Manager Service (Cmd_Mgr)  ... Failed!\n [Warning]! An error occured while initializing Command Manager Service (Cmd_Mgr)."); }

while(g_msgQueue.getLast() != 0xFF){ 
    if(g_msgQueue.getLast() == 0xFE){
        CLog->out("\n == WARNING == SERVICE RESTART MESSAGE WAS RECIEVED .... REBOOTING ALL SECONDARY THREADS! "); // Todo, _endthread // and nicely reboot

    }
}
return 0;

It turns out I was adding values in a different file.
Notice the:

LockSection lc(&crt,&err);
CLog->out(" [ Adding message = 0x45 ] Action : None \n");
g_msgQueue.Add(0x45);
CLog->out(" [ Adding message = 0xFD ] Action : Stalling Backgrounder Thread...\n");
g_msgQueue.Add(0xFD);
lc.ForceCSectionLeave();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:38:00+00:00Added an answer on May 26, 2026 at 12:38 am
    • the function Add() will always print out the first element you added: if you ad 69, 45, 89, 34 it will always print 69 that is the first added element

    • You don’t need to derive from MESSAGE_LIST (vector or queue), you are just using them in the m_pList member

    • if m_pList is null your program will crash because you are not returning any value when you are supposed to

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.