Monday, November 12, 2012

memcpy() and memmove()




                                                    memcpy() and memmove()


memcpy does a mindless copy, regardless of whether there are shared bytes between the source and destination: 

 void *memcpy (void *dst, const void *src, size_t n)

 { 

   char *a = dst;

   const char *b = src; 

   while (n--)


    *a++ = *b++;



       }

   return dst;


 }



memmove does backward copy  and takes care of overwritten value of shared bytes:


void *memmove(void *dst, const void *src, size_t n) 

{ 

 char *a = dst; 

 const char *b = src;



 if (a <= b || b >= (a + n)) {

/* No overlap, use memcpy logic or can use memcpy itself(copy forward) */ 

 while (n--) 

 *a++ = *b++;


}


else { 

 /* Overlap! Copy backward to fix */ 

 a = a + n - 1; 

 b = b + n - 1;




while (n--) 

 *a-- = *b--; 

 } 

 return dst;

Sunday, October 21, 2012

SINGLY LINKED LIST and Different OPERATION on it





#include
#include
struct node {
       int data;
       struct node *next;
       }*start;
      
main()
{
      int choice,n,m,position,i;
      start=NULL;
      while(1)
      {
              printf("1.Create List\n");
              printf("2.Add at begining\n");
              printf("3.Add after\n");
              printf("4.Delete\n");
              printf("5.Display\n");
              printf("6.Count\n");
              printf("7.Reverse\n");
              printf("8.Search\n");
              printf("9.Quit\n");
              printf("Enter Your Choice:");
              scanf("%d",&choice);
              switch(choice)
              {
                            case 1:
                                 printf("How many nodes you want:");
                                 scanf("%d",&n);
                                 for(i=0;i                                 {
                                                 printf("Enter the Element: ");
                                                 scanf("%d",&m);
                                                 create_list(m);
                                 }
                                 break;
                            case 2:
                                 printf("Enter the element :");
                                 scanf("%d",&m);
                                 addatbeg(m);
                                 break;
                            case 3:
                                 printf("Enter the element: ");
                                 scanf("%d",&m);
                                 printf("Enter the position after which element is inserted: ");
                                 scanf("%d",&position);
                                 addafter(m,position);
                                 break;
                            case 4:
                                 if(start==NULL)
                                 {
                                            printf("List is empty\n");
                                            continue;
                                 }
                                 printf("Enter the element for deletion:");
                                 scanf("%d",&m);
                                 del(m);
                                 break;
                            case 5:
                                 display();
                                 break;
                            case 6:
                                 count();
                                 break;
                            case 7:
                                 rev();
                                 break;
                            case 8:
                                 printf("Enter the element need to be searched:");
                                 scanf("%d",&m);
                                 search(m);
                                 break;
                            case 9:
                                 exit(1);
                            default:
                                 printf("Wrong Choice\n");
                      }
              }
   
      }
create_list(int num)
{
   struct node *temp,*q;
   temp = malloc(sizeof(struct node));
   temp->data=num;
   temp->next=NULL;
   if(start == NULL)
    {
        start=temp;
    }
    else
    {
        q=start;
        while(q->next!=NULL)
            q=q->next;
        q->next=temp;                           
    }
}
addatbeg(int num)
{
        struct node *temp;
        temp=malloc(sizeof(struct node));
        temp->data=num;
        temp->next=start;
        start=temp;
}
addafter(int num, int pos)
{
        struct node *temp ,*q;
        int count=1;
        temp=malloc(sizeof(struct node));
        temp->data=num;
        q=start;
        while(q!=NULL)
        {
         if(pos==count)
         {
                       temp->next=q->next;
                       q->next=temp;
         }
         count++;
         q=q->next;
        }
}       
del(int num)
{
        struct node *temp,*q;
        if(start->data==num)
        {
                       temp =start;
                       start=start->next;
                       free(temp);
                       return;
        }
        q=start;
        while(q->next->next!=NULL)
        {
         if(q->next->data==num)
             {
                                   temp=q->next;
                                   q->next=temp->next;
                                   free(temp);
                                   return;
              }       
              q=q->next;
        }
        if(q->next->data==num)
        {
                              temp=q->next;
                              free(temp);
                              q->next=NULL;
                              return;
        }
        printf("Element not found in the List\n");
}      

display()
{
         struct node *q;
         if(start==NULL)
         {
                        printf("Empty List\n");
                        return;
         }
         q=start;
         printf("Elements are:");
         while(q!=NULL)
         {
                             if(q->next!=NULL)
                             printf("%d,",q->data);
                             else
                             printf("%d.\n",q->data);
                             q=q->next;
           
         }
         printf("\n");
}       
count()
{
       struct node *q;
       int cnt;
       if(start==NULL)
       {
                      printf("Zero Element\n");
                      return;
       }
       q=start;
       while(q!=NULL)
       {
            cnt++;
            q=q->next;
                      
       }
       printf("The number of Elements in the list:%d\n",cnt);
}
rev()
{  
     struct node *p1,*p2,*p3;
     if(start->next==NULL)
     {
                          printf("Only one Element is present\n");
                          return;
     }
     if(start->next->next ==NULL)
     {
                          p1 = start;
                          p2= p1->next;
                          p2->next= p1;
                          p1->next=NULL;
                          start = p2;
                          return;
     }
     p1=start;
     p2=p1->next;
     p3=p2->next;
     p1->next=NULL;
     p2->next=p1;
     while(p3!=NULL)
     {
                    p1=p2;
                    p2=p3;
                    p3=p3->next;
                    p2->next=p1;
     }
     start=p2;                                        
}
search(int num)
{
    struct node *q;
    q=start;
    int pos =1;
    while(q!=NULL)
    {
           if(q->data==num)
           {
                    printf("Element %d found at pos=%d\n",num,pos);
                    return;
           }
           pos++;
           q=q->next;
    }
    if(q==NULL)
    printf("Element %d nod found in the list\n",num);
}

Friday, September 14, 2012

SYSTEM CLOCKS



CLOCK_REALTIME : it gives the access to the real time clock (RTC) , i.e. the one that stores the current date and time.

     A key difference between an RTC and the system clock is that RTCs run even
     when the system is in a low power state (cpu Idle), and the system  clock can't. 
     Until it is initialized, the system clock can only report time since system boot, not 
     since the POSIX Epoch.  So at boot time, and after resuming from a system low 
     power state, the system clock will often be set to the current wall clock time using 
     an RTC.



CLOCK_MONOTONIC : it gives the access to a clock ( cpu ticks ) that never goes back in time .It takes the CPU Hz.

 It goes off when there will be no Hz ( cpu Idle state) . So when again CPU gets up ,
 it adds the sleeping time using another components input timerkeeping timer,
 basically a rough time. So it should be used in the usecase wherever we need delta 
 of time.Irrespective of cpu state during playback , whenever we do clock_gettime ,this
 clock will be there.
Basically these are clock_ids which provides clock source when we use clock_gettime()

otherwise to get the phone time , we can use gettimeofday() , this will change whenever there
will be change in wall time.

Wednesday, September 12, 2012

Android Streaming



    Streaming on Android Phone
  • HTTP , PDL , Youtube 
  • HLS - Live streaming
  • DRM - Widevine
  • RTSP