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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:45:58+00:00 2026-05-18T03:45:58+00:00

We are trying to produce a library component which will perform asynchronous calls. For

  • 0

We are trying to produce a library component which will perform asynchronous calls.
For various reasons this needs to have a C like interface, so we are providing a large set of static functions as the interface to the library.

We also need the user to have control over the memory. So most functions look something like

int myLibFunction(void* data, size_t data_size);

I’m trying to replace this with a smarter Future object so that we don’t use void pointers and so that the access to the data is synchronised between threads. Ideally the calls would look something like:

Future<T> {
  T m_data;
}

static int myLibDoJob1(Future<Func1Data>& data);
static int myLibDoJob2(Future<Func2Data>& data);

main()
{
   Func1Data m_data;
   Func2Data m_data2;
   Future<Func1Data> future1(m_data);
   Future<Func2Data> future2(m_data2);
   int ret=0;

   ret = myLibDoJob1(future1);
   ret = myLibDoJob2(future2);
}

This is a fairly clean interface and the interface forces type safety at compile time. However the problem I have is that I’m creating a queue of jobs to perform internally. However due to the Futures being different sizes I can’t create a std:queue of them, I had hoped to be able to create a std::queue, with Job containing a Future* however this isn’t valid.

I’ve also tried having Job contain Future where all the Data classes derive from ParentData also to no avail.

The problem is very similar to the one of having containers of smart pointers. Due to the nature of the team I work in I won’t be able to expose any boost objects outside the library and I will be chased around with a cricket bat if I make Future polymorphic.

Its important that the user side code to the library has control over where the data actually is.

Regards,
Iain

  • 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-18T03:45:59+00:00Added an answer on May 18, 2026 at 3:45 am

    Either you will use C++ to do polymorphism or you will reimplement polymorphism with void*. The easiest way to solve your problem is to give Future<T> a base class that doesn’t depend on T. Usually I do it like this:

    class Future {};
    
    template<class T>
    class FutureOf : public Future {};
    

    Then, you can create containers of Future* and have some type-safety.

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

Sidebar

Related Questions

I have been trying to produce a statically linked single binary version of my
I'm currently trying to create a kernel module that will produce data based on
I'm trying to do this (which produces an unexpected T_VARIABLE error): public function createShipment($startZip,
I'm trying to produce sheets of photographs with captions arranged in a grid using
I'm trying to produce just the day number in a WPF text block, without
I'm trying to produce a report that has multiple grouping but does not just
I'm trying to produce a pretty simple XML schema for an XML similar to
I am accessing a business class using an ObjectDataSource and trying to produce output
I'm trying to read a file to produce a DOM Document, but the file
I'm trying to create an algorithm in C# which produces the following output strings:

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.