Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Wed, Dec 4, 2013 at 2:59 PM, David Buchan pdbuc...@yahoo.com wrote: // Allocate memory on the heap, not stack. msgdata = (msgdatas *) malloc (1 * sizeof (msgdatas)); msgdata-textview = (int *) malloc (1 * sizeof (int)); message = (char *) malloc (1024); The only blocks of memory

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Vine
On Tue, 3 Dec 2013 19:59:22 -0800 (PST) David Buchan pdbuc...@yahoo.com wrote: ok, I may be getting somewhere. I did some reading on heap memory versus stack. Here's a vastly simplified example program which doesn't use GTK+, but I'm using to demonstrate my plan of attack. I use a

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Wed, Dec 4, 2013 at 9:28 PM, Chris Vine ch...@cvine.freeserve.co.uk wrote: Otherwise, have you considered perhaps using something like the python bindings for GTK+? These have a binding for g_idle_add() and handle all the memory allocation for you. I recommend using the

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Tue, 3 Dec 2013 19:59:22 -0800 (PST) David Buchan pdbuc...@yahoo.com wrote: ok, I may be getting somewhere. I did some reading on heap memory versus stack. Here's a vastly simplified example program which doesn't use GTK+, but I'm using to demonstrate my plan of attack. I use a

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread jcupitt
Here's a tiny, complete program that does almost what you want. It's gtk2, but should work fine with gtk3. It just updates a status bar, but it'd be easy to make it do a textview instead. John ___ gtk-app-devel-list mailing list

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread jcupitt
Oh dear, I think my attachment got munched (thanks Chris). Try here: http://pastebin.com/PsG2UDkY On 4 December 2013 13:31, jcup...@gmail.com wrote: Here's a tiny, complete program that does almost what you want. It's gtk2, but should work fine with gtk3. It just updates a status bar,

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On 4 December 2013 13:31,  jcup...@gmail.com wrote: Here's a tiny, complete program that does almost what you want. It's gtk2, but should work fine with gtk3. http://pastebin.com/PsG2UDkY It just updates a status bar, but it'd be easy to make it do a textview instead. John

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Wed, Dec 4, 2013 at 2:59 PM, David Buchan pdbuc...@yahoo.com wrote:   // Allocate memory on the heap, not stack.   msgdata = (msgdatas *) malloc (1 * sizeof (msgdatas));   msgdata-textview = (int *) malloc (1 * sizeof (int));   message = (char *) malloc (1024); The only blocks of memory

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:00 AM, David Buchan pdbuc...@yahoo.com wrote: Things I've learned yesterday are: 1. strdup() (I've never seen or used it before) 2. what the heck heap and stack mean (still more to learn there) 3. a more general and flexible solution is probably to use asynchronous

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:18 AM, David Buchan pdbuc...@yahoo.com wrote: What I mean is, is it kosher to have: msgdatas msgdata; // I'd pass msgdata as arg. to g_idle_add() I suppose. No, it's most definitely not, unless you can guarantee that (a) the function that called this will still be

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Thu, Dec 5, 2013 at 2:00 AM, David Buchan pdbuc...@yahoo.com wrote: Things I've learned yesterday are: 1. strdup() (I've never seen or used it before) 2. what the heck heap and stack mean (still more to learn there) 3. a more general and flexible solution is probably to use asynchronous

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:56 AM, David Buchan pdbuc...@yahoo.com wrote: Making the pointer to textview global would indeed simplify things enormously. I guess I avoid global variables like the plague, having been told to for years. Also wanted to make the idle function generic. Yeah, lots of

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:56 AM, David Buchan pdbuc...@yahoo.com wrote: PS. Socket programming is great fun! ( http://pdbuchan.com/rawsock/rawsock.html ) Absolutely! I don't usually use raw sockets though - I tend to use TCP primarily, and sometimes UDP or ICMP, but not raw. TCP sockets equal

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Vine
On Thu, 5 Dec 2013 03:06:59 +1100 Chris Angelico ros...@gmail.com wrote: [snip] As promised, here's a simple Pike program that listens for socket connections. [snip] See how much effort goes into making sure everything's thread-safe? The same amount, because this isn't even threaded -