Saturday, November 5, 2011

UILabel, important info

You mention threads. Be aware that UIKit controls, such as UILabel, can only be updated from the main thread. Make sure you are only attempting to set the label's text from the main thread and then verify if you are still having issues.

EDIT due to question edit:

First, -setNeedsDisplay only tells the view it needs to redisplay the next time the screen is refreshed, it does not force a display at that time.

Second, the iPhone screen draws at about 60 hz. This means there is an update every 0.016666 or so seconds. You're trying to update much faster than that, so only about every 160th of your updates will actually be displayed.

Third, and probably most important, you don't seem to be making any threads, unless you call -startUpdateStatusThread from a background thread. Either way, once you hit -updateFrequently everything is back on the main thread. With the frequency you are scheduling that timer, you are probably overloading the CPU and making it so that the system does not have time to draw the label. So even though you are setting new text, you aren't giving it a chance to render. You need to reduce the frequency of that timer, and you probably need to rethink whatever it is you're trying to do.

Wednesday, July 14, 2010

Wednesday, April 14, 2010

Multithreading programming in Win32

Here is the simple application that creates 100 threads and each thread executes the StartThraed() function


DWORD WINAPI StartThread(LPVOID threadID)
{
int tid = atoi((char *)threadID);
cout< return 0;
}

int main()
{
HANDLE hThread1;
DWORD dwGenericThread;
char threadID[10];

for (int x = 0; x < 10; ++x)
{
for (int y = 0; y < 10; ++y)
{
sprintf(threadID, "%d", y*10+x);
hThread1 = CreateThread(NULL,0,StartThread,&threadID,0,&dwGenericThread);
if(hThread1 == NULL)
{
DWORD dwError = GetLastError();
cout<<"SCM:Error in Creating thread"< return 0;
}
WaitForSingleObject(hThread1,INFINITE);
CloseHandle(hThread1);
}
}
}

Thursday, April 8, 2010

Singleton class, a different way

We all knew that, the below class will give us only one instance of the class.
class Singleton
{
private:
static Singleton* singleton;
private:
Singleton();
public:
static Singleton* getIntsance();
};

Just think that is there any other way to do the same. Yes, we have onother solution for it. See below

class Singleton
{
private:
static Singleton* singleton;
private:
~Singleton();
public:
static Singleton* getIntsance();
};

Destructor is in private scope now.

Tuesday, March 30, 2010

how to find out middle element of a linked list in a single traversal

program:

Node* findMidNode(Node* start)
{
Node* midNode = start;
while(start != NULL || start->next != NULL)
{
midNode = midNode->next;
start = start->next->next;
}
return midNode;
}

Algorithm
:

midNode is pointing to next of the midNode in every iteration and
start is pointing to next to next (i.e., increment 2) of start in every iteration.
so, when start is at the end, then midNode is pointing to middle element of the List.

reverse the linked list using recursive method


Algorithm:

Here the algorithm is, pointing p and q to the next elements in every iteration. Once we reached the end, then start pointing to back, i.e.., q->next = p;


//structure
struct Node
{
int data;
struct Node* next;
};

//global variables...
struct node* start = NULL;
struct node* p = NULL;
struct node* q = NULL;

//assusme that we have added some elements into the List, and start
//is pointing to first element in the list
reverseList(start);

void reverseList(struct Node* node)
{
if (node->next == NULL)
break;

p = node->next;
q = p->next;
if (q->next != NULL)
{
reverseList(q);
}
else
{
start->next = NULL;
start = q;
}
q->next = p;
}

how to print the bits in a reverse order (without using any variable)

Suppose, 123 is represented as 01111011. But we have to print it in reverse order, i.e.., 11011110

program

int main()
{
int i = 123;
while(i!=0)
{
if (i & 1)
printf("1");
else
printf("0");
i >>= 1;
}
}