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



On Wed, Dec 4, 2013 at 2:59 PM, David Buchan <pdbuchan 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 that need to be on the heap are those that
will be passed around. These ones don't go anywhere, so they could be
automatic (ie on the stack).

If it helps, think of every block of memory as having an owner. When
you call strdup() or malloc() or anything like that, you get a pointer
to a block of memory which you now own. You can then pass that pointer
to another thread and abandon it, and the other thread now owns that
memory. Ultimately, the owner of the memory frees it, and then nobody
owns it.

ChrisA


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]