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 8212867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:54:57+00:00 2026-06-07T10:54:57+00:00

I have an implementation of a queue, something like template <typename T> queue<T> with

  • 0

I have an implementation of a queue, something like template <typename T> queue<T> with a struct QueueItem { T data;} and I have a separate library that times the passage of data across different places (including from one producer thread to consumer thread via this queue). In order to do this, I inserted code from that timing library into the push and pop functions of the queue so that when they assign a BufferItem.data they also assign an extra member i added of type void* to some timing metadata from that library. I.e. what used to be something like:

void push(T t)
{
  QueueItem i;
  i.data = t;
  //insert i into queue
}

became

void push(T t)
{
  QueueItem i;
  i.data = t;

  void* fox = timinglib.getMetadata();
  i.timingInfo = fox;
  //insert i into queue
}

with QueueItem going from

struct QueueItem
{
 T data;
}

to

struct QueueItem
{
  T data;
  void* timingInfo;
}

What I would like to achieve, however, is the ability to swap out of the latter struct in favor of the lighter weight struct whenever the timing library is not activated. Something like:

if timingLib.isInactive()
 ;//use the smaller struct QueueItem
else
 ;//use the larger struct QueueItem

as cheaply as possible. What would be a good way to do this?

  • 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-06-07T10:54:59+00:00Added an answer on June 7, 2026 at 10:54 am

    You can’t have a struct that is big and small at the same time, obviously, so you’re going to have to look at some form of inheritance or pointer/reference, or a union.

    A union would be ideal for you if there’s “spare” data in T that could be occupied by your timingInfo. If not, then it’s going to be as ‘heavy’ as the original.

    Using inheritance is also likely to be as big as the original, as it’ll add a vtable in there which will pad it out too much.

    So, the next option is to store a pointer only, and have that point to the data you want to store, either the data or the data+timing. This kind of pattern is known as ‘flyweight‘ – where common data is stored separately to the object that is manipulated. This might be what you’re looking for (depending on what the timing info metadata is).

    The other, more complex, alternative is to have 2 queues that you keep in sync. You store data in one, and the other one stores the associated timeing info, if enabled. If not enabled, you ignore the 2nd queue. The trouble with this is ensuring the 2 are kept in sync, but that’s a organisational problem rather than a technical challenge. Maybe create a new Queue class that contains the 2 real queues internally.

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

Sidebar

Related Questions

I currently have a concurrent queue implementation that uses a BlockingQueue as the data
Is there any Queue data structure implementation that comes with C or will I
I have a priority queue implementation in C# that I want to add a
Does Ruby's standard library have a priority queue implementation?
I have a very simple queue implementation that wraps a fixed array. It contains
I know that it's OK for a pure virtual function to have an implementation.
I have several queues that all extend a Queue class. I want to do
I have a program that has a ton of sensors producing data at a
I have an application which uses an im-memory implementation of Queue. I need to
I have something like Message forwarder / router for MQ messages. I'm trying to

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.