Wednesday, December 11, 2013

Dynamic Memory Allocation in C


Hi,
In this, I would like to post the program that was given for my juniors in my school. They were very new to Programming and I was standing there helping them sot out their problems while implementing it. They were asked to implement a 2D Dynamic Array. I tried to explain them as far as I could in this blog. Below is the explanation of the concept behind 2D Dynamic Array Creation.
Dynamically, if we wanna create anything, we have to go for "Pointers". Pointers  are capable of storing memory locations. We can create memory locations of our desired size dynamically and assign them to pointers. So, a pointer can very well suit our dynamic needs.
Below is a program fragment for creating 2d dynamic array. The Program actually is meant for our Juniors in Lab. They were asked to implement a 2d dynamic array for constant rowsize and variable column size.
source code:
#include<stdio.h>
#include<malloc.h>
int main(){
int **p; int i, j, x,y[10],tmp;
printf("Enter Rowsize x");
scanf("%d",&x);
//user-casting the null pointer for
//the demanded amount of memory, here, "x" many
//memory locations are created and the starting
//address of the first memory location is returned via
// a null pointer. This is assigned to the pointer
//for the pointer
p = (int **)malloc(x*sizeof(int *));
printf("Enter varying ColumnSize for each row");
for(i=0;i<x;i++)
{
printf("nrow%d:",i+1);
scanf("%d",&y[i]);
//pointer for the column data *(p+i)
//has to be the size of the column data
//y[i] many memory locations of size
//int (2 bytes) is created and the starting
//address is returned via a null pointer
//which is user-casted and used
p[i]= (int *)malloc(y[i]*sizeof(int *));
}
printf("nEnter elementsn");
for(i=0;i<x;i++)
for(j=0;j<y[i];j++){
scanf("%d",&tmp);
p[i][j] = tmp;
}
printf("nEntered elementsn");
for(i=0;i<x;i++){
for(j=0;j<y[i];j++)
printf("%dt",p[i][j]);
printf("n");
}
return 0;
}

That's it
Happy Exploring :)

CloudSim Setup and Running Simulation using Eclipse in Linux

Hi,
Today, I'm gonna explain how to setup CloudSim Environment in your Linux Machine using Eclipse IDE. CloudSim is actually a Library for Cloud Simulation written in Java Language, that can be added to our Source files. So, Essentially, Our Linux Computer should have Java Development Kit installed in it. It can be installed by typing the following command in your terminal. Skip the sections if Java an Eclipse Installations are already done.

Step 1. Installation & Verification of Java Compiler

sudo apt-get install openjdk-7-jdk

You can verify the installation of JDK, by typing the below command in your terminal.

javac -version               or            java -version

Step 2. Installation of Eclipse

On execution of the above commands, the version of the Java Compiler and/or the Java RunTime Environment will be displayed. If the JDK version is displayed, you are ready to go ahead and install Eclipse. Eclipse can be installed using the following command in your terminal.

sudo apt-get install eclipse

Note, that all the installations can also be done in a graphical way using Software Updater in Ubuntu.

Step 3. Creation of Project (for Complete Beginners)

Now that, we have installed Java Compiler and Eclipse, we can create a new project and add the Libraries to it. Create a new Project in Eclipse. This can be done using File->New->Project->Java Project; Give a name to your Project.

Step 4: CloudSim Library Adding

Currently, there is no source file associated with it. Let's firstly add the libraries to it. Right Click the Project and add folder named "libs" to it. Assuming you had already downloaded and extracted the CloudSim Library.

Go to the Extracted Folder and locate the jars in the "jars" folder. Copy the jar, cloudsim-3.03.jar and paste it inside the newly created folder in the project.Right-Click the Jar Build Path -> Add to Build Path. Immediately the jars will be added in the Referenced Libraries.

FCFS Task Allocation in CloudSim

Hi All,
Today I'm going to write an Application in Java using CloudSim 3.0.3 Library, which simulates the Cloud and performs Tasks Allocation to the VMs on the basis of FCFS, First-Come-First-Served Scheduling Policy, in the Cloud. There are many ways to write this program. I'm writing in one of those ways. The Post is for all who know the basics of OOPs and Java Platform. Let's first see the architecture of CloudSim. It is shown below.

In CloudSim, UserCode forms the top layer, where the user creates specification and scheduling policies for the Cloud Environment. Below Diagram shows the Classes or Entities that form the CloudSim Library and their relationships.


Let's now see the sequence diagram of any Cloudsim Application.

 From all these diagrams, we must have understood the working of CloudSim Application. Finally, let's see the exact working style of Cloudsim Entities in the below diagram.

 

Tuesday, December 10, 2013

Irandam Ulagam Story Teller - A Fan's View

               The Story revolves around Madhu Bala Krishnan, a Lecturer in a Professional College, who is an obedient and too-good son. He falls in love with a girl named Ramya, who is a Medical College Student after denying her proposal. He manages to win her heart only to lose her within a short span. He becomes heart-broken and added to it his beloved father also dies. To his surprise, his father comes alive back to him and asks him to go in search for her, because "Love can do anything" and he can find her even when she is dead.
 
              Parallel-ly, in the other World, Maravan, the son of the Country's Warfield commander likes an orphan girl named Varna so much and becomes so desperate that he kills the "Unkillable Lion" for the sake of getting her. Pleased by his act, the King along with the people of the kingdom who treats women as less-valued creatures, marries Maravan with Varna against the wish of Varna. Infuriated by the Marriage, Varna tries to kill herself. Varna is saved by the GodMother of the Country, called "AMMA". But, the King banned her from the country for misbehaving.

                    The Planet entirely never had seen a flower because of the absence of Love in that Planet. The Planet-mates had treated Women as less-human-beings for thousands of years. Because of that, there was no Love in that Planet. AMMA foresaw the Destruction of the Planet because of the absence of Love in their planet. So, she with her magical powers brings Madhu from the Earth to their Planet via Maravan to teach LOVE to the people. Madhu who was in-full-of-love with Ramya sees Varna who looked the same as Ramya. Maravan wants to re-unite with Varna and Varna wants to be free without under anyone's control. What happens ? becomes the core of the Screen play.

- a Selvaraghavan Fan

Mayakkam Enna Story Teller - A Fan's View

     "Mayakkam Enna" - a new Tamil film, directed by my most favourite director, SELVARAGHAVAN sir. A film from him, after a pretty small gap, after "Ayirathil Oruvan".Each and every movie of him, has a unique flavour, liked by most of the youths (like me),OK lemme go into the review.

   Kartheek Swaminathan (Dhanush) is not just like an ordinary man, his parents left him all alone with his sister after an accident, 5 yrs ago. He's taken care by his friend Sundar and his family. It sounds great to see a father allowing his son's real big gang to live in his home. Kartheek dreamt of becoming a Wildlife photographer. One day(sorry night), Sundar brings with her a girl named Yamini (Richa), introducing her as his dating friend.

   Kartheek often teases Yamini somewhat badly, but Yamini creates oppurtunities to meet him, so as to settle the issues. In the course, they fell in love with each other. Kartheek, in a state of betraying his friend cum care taker, tries to leave her, but Yamini wouldn't let him go...
Dhanush as Kartheek Swaminathan, Richa Gangopadhyay as Yamini, have played their role well, it's better to say, they lived like the characters. Music by G. V. Prakash Kumar, Cinematography by Ramji.

I would rate this film 5 stars...
Please watch movies in theatres and help-promote Making Good Films

- a Selvaraghavan fan