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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:59:04+00:00 2026-05-17T16:59:04+00:00

Here is my issue. I have a class to create timed events. It takes

  • 0

Here is my issue.
I have a class to create timed events. It takes in:

A function pointer of void (*func)(void* arg)

A void* to the argument

A delay

The issue is I may want to create on-the-fly variables that I dont want to be a static variable in the class, or a global variable. If either of these are not met, I cant do something like:

void doStuff(void *arg)
{
   somebool = *(bool*)arg;
}

void makeIt()
{
bool a = true;
   container->createTimedEvent(doStuff,(void*)&a,5); 
}

That wont work because the bool gets destroyed when the function returns. So I’d have to allocate these on the heap. The issue then becomes, who allocates and who deletes. what I’d like to do is to be able to take in anything, then copy its memory and manage it in the timed event class. But I dont think I can do memcpy since I dont know the tyoe.

What would be a good way to acheive this where the time event is responsible for memory managment.

Thanks

I do not use boost

class AguiTimedEvent {
    void (*onEvent)(void* arg);
    void* argument;
    AguiWidgetBase* caller;
    double timeStamp;
public:
    void call() const;

    bool expired() const;
    AguiWidgetBase* getCaller() const;
    AguiTimedEvent();
    AguiTimedEvent(void(*Timefunc)(void* arg),void* arg, double timeSec, AguiWidgetBase* caller);
};

void AguiWidgetContainer::handleTimedEvents()
{
    for(std::vector<AguiTimedEvent>::iterator it = timedEvents.begin(); it != timedEvents.end();)
    {
        if(it->expired())
        {

            it->call();
            it = timedEvents.erase(it);
        }
        else
            it++;
    }
}

void AguiWidgetBase::createTimedEvent( void (*func)(void* data),void* data,double timeInSec )
{
    if(!getWidgetContainer())
        return;
    getWidgetContainer()->addTimedEvent(AguiTimedEvent(func,data,timeInSec,this));
}


void AguiWidgetContainer::addTimedEvent( const AguiTimedEvent &timedEvent )
{
    timedEvents.push_back(timedEvent);
}
  • 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-17T16:59:04+00:00Added an answer on May 17, 2026 at 4:59 pm

    Why would you not use boost::shared_ptr?

    It offers storage duration you require since an underlying object will be destructed only when all shared_ptrs pointing to it will have been destructed.

    Also it offers full thread safety.

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

Sidebar

Related Questions

I stumbled upon an issue with event namespacing while developing a jQuery plugin. here
I have a widget that currently takes a random string from an array and
I have a console application that sends customized emails (with attachments) to different recipients
I have a Console App created in VS 2010 targeting .NET 4.0. According to
I have a situation where I user IoC (WindsorContainer) in a .Net web application,
I am having some troubles thinking through a design issue and thought that the
I get the message literal does not match format string. For instance, here are
I'm having some issues with my code. This is probably due to some design
Although I'm coding in ObjC, This question is intentionally language-agnostic - it should apply
I am having trouble with XMLTextWriter.WriteStartElement throwing an exception: System.InvalidOperationException when trying to write

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.