GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 21, 2014 6:00 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to pass a struct within a struct to GSourceFunc?
PostPosted: Fri Jun 08, 2012 5:27 pm 
Offline

Joined: Fri Jun 08, 2012 5:21 pm
Posts: 2
Code:
typedef struct{
//...
}S;

struct MS{
//..
S *St;
};

static gboolean AL_Calback(gpointer data){
    S *St = (S*)user_data;
    St->Something = SomethingElse;
    return TRUE;
}

int main (int argc, char *argv[]){

    //...
    MS *MainStruct = gnew0(MS, 1);
    Mainstruct->St = gnew0(S, 1);
    clutter_threads_add_timeout_full(G_PRIORITY_HIGH, 100, AL_Callback, MainStruct->St, NULL);
    //...
}


Or this?

Code:
typedef struct{
//...
}S;

struct MS{
//..
S St;
};

static gboolean AL_Calback(gpointer data){
    MS *MV = (MS*)user_data;
    MV->S.something = SomethingElse;   
    return TRUE;
}

int main (int argc, char *argv[]){

    //...
    MS *MainStruct = gnew0(MS, 1);
    clutter_threads_add_timeout_full(G_PRIORITY_HIGH, 100, AL_Callback, MainStruct, NULL);
    //...
}


Or is there a better way?


Last edited by MVC+ on Fri Jun 08, 2012 6:48 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How to pass a struct within a struct to GSourceFunc?
PostPosted: Fri Jun 08, 2012 5:51 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Hi,

Both are valid ways of passing data, depending on how you want to assign your memory allocation. In both your examples you have very basic coding errors which make understanding what you want hard to make out.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to pass a struct within a struct to GSourceFunc?
PostPosted: Fri Jun 08, 2012 6:43 pm 
Offline

Joined: Fri Jun 08, 2012 5:21 pm
Posts: 2
Hi errol.

I am making an audio player using clutter, and openAL. This function is to check if an openAL buffer has been processed and if so un-queue it, fill with new data, and re-queue. I have other functions which do things like change the position, draw a signal level meter, and spectral analyzer. And they need access to some of the same data which my openAL callback function uses, as well as some other clutter objects.

I'm not very experienced as a programmer, and have been slightly confused about how to best manage these things. I just want to make the openAL callback as efficient as possible. I thought maybe the first way might be faster, but I really don't have much of a clue.

I noticed a few of the errors and edited my first post. Do you still see mistakes?

Thanks


Top
 Profile  
 
 Post subject: Re: How to pass a struct within a struct to GSourceFunc?
PostPosted: Mon Jun 11, 2012 6:41 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
With such a small snippet of code it is very hard to tell what is an error or what has been missed out completely.

I do not know the OpenAL library. From experience writing an audio application and having a GUI is not a simple thing. You will almost certainly need to use threads. Any data shared between the threads must be accessed in a thread safe way. Because certain parts must be done with out causing the audio to glitch certain time critical areas can not use mutex locks and other communication methods must be used.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: newguy and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group