Friday, November 24, 2006

Dynamic Memory Allocation in C, C++ - my strange experiences with gcc and g++

Yesterday i learnt few strange things about malloc() in C and new, delete operators in C++.
Compiler referred is gcc for C, and g++ for C++ programs.

First one:
int *a=malloc(sizeof(int) *0); //i am trying to allocate 0 bytes of memory and pointing that location with pointer a.
==> What should happen, Segmentation fault( run time error) , since allocating 0 bytes of memory is absurd and then referencing it through a pointer a is too wrong. It went through compilation and run perfectly on 'dereferencing' as a[0]=5, a[1]=2,... .
==> But i get segfault when i am trying to allocate -ve bytes of memory.

Second one:
int *a= new int[0];
==> the same effect with 0 size memory allocation and runtime error when trying to allocate (-ve)size of memory.

Third one:
This one, i strongly beleive that it sould raise runtime error, as it is mentioned in C++ standards.
int* a=new int[10];
......
delete a; //Here it should be delete[] a;
==> When an array of objects are created with new operator, while deleting all objects, we should use delete[], instead of delete; since delete will only delete that object.

Fourth one:
Do you think that on freeing or deleting the dynamic memory, the contents/memory locations will be deleted permanantly? No, it shouldn't be. The compiler will just cut of those associated links and the memory locations still with the content that we have assigned. If u want to try, assign the locations to other pointer before freeing/deleting.
My experience is:
int *a=malloc(sizeof(int)*4);
a[0]=1;a[1]=2;a[2]=3;a[3]=4;
int *t;
t=a;
free(a);
printf("%d , %d , %d , %d ",t[0],t[1],t[2],t[3]);
//Answer is "0 , 2 , 3 , 4"

int *a=new int[4];
a[0]=1;a[1]=2;a[2]=3;a[3]=4;
int *t;
t=a;
delete(a);
printf("%d , %d , %d , %d ",t[0],t[1],t[2],t[3]);

//Answer is "0 , 2 , 3 , 4"

==> I am not able to figure out the logic behind making the value of base address to 0 upon deleting. If it is to make value of deleted location as '0', then it should be with all the locations that are dynamically created. But it isn't. And also one more thing is 'write' operation is more costly than delinking.

Your comments are appreciated, if you have proper reasons.

Tuesday, November 21, 2006

Thy Self in Johari Window - an update

This post is a follow-up to my previous post, and i thought that i could update it. Thanks to those for putting their effors on letting me know better.
If you want to know more about johari window (Jeo-Harry window), please visit the following links.

http://en.wikipedia.org/wiki/Johari_window
http://kevan.org/johari
http://www.noogenesis.com/game_theory/johari/johari_window.html
http://business.nmsu.edu/~dboje/503/johari_window.htm

Saturday, November 18, 2006

BhimaShankar - One of the 12 Jyotirlingas


Last Saturday i went to BhimaShankar, which is located in the Western Ghats mountain range near to Pune. The distance is 110 km from Pune, and we (me, my friend Sridhar and two of his roommates) went by a cab. The journey is thrilling and the place is located in the far end of the Sahyadri Mountain range. Our trip is just a Half Day only, as we just want to dharshan the Swayambhu Linga. Bhimashankar is also the origin of Bhima River which merges up with Krishna river at Raichur.

This jyothirlinga is one of the famous and ancient ones, which was associated with lord 'Shiva', and has formed upon destroying the demon 'Tripurasara'. If you want to know more about the story and, its formation, refer to this page.

It is believed that the ancient shrine was erected over a Swayambhu Linga or a Self Emanated Shiva Linga. Thus the Linga is exactly in the centre of the floor of the Garbagriha or the Sanctum.

This place gives a wonderful view of Mumbai (ofcourse, which we hav been able to view due to fog), and the hill stations around. Its not more than a pilgrim’s paradise, also a trekker’s delight and traveller’s sojourn. But the ghat road is not so good, and if you opted to go by bus, you will definitely face inconvenience.

This place is good for trekkers as one of the hill is almost 90-deg slope, in the Mumbai side, and i came to know that many trekkers love to climb it. And it is also an extremely dangerous place, if slipped, 100% chances of no survival.

In the near bottom the main hill, there is one point which is said that as origin of the Bhima River. But the disappointing thing is that the Linga was covered up by a silver coating. We came to know that the cover will be released daily twice, once in the early morning 4.30 , and midday 12.00-12.30 pm. The darshan time starts early from 5.30AM and Maha Puja went at 12.00-12.30pm.
Some of the pics that we have taken in the journey.









Thursday, November 09, 2006

I am delighted (and a bit busy..)

ఈ రోజు నాకు చాల సంతోషంగా ఉంది. కావలసినంత తెలుగును చదివాను. కొన్ని రోజుల నుంచి నేను అనుకుంటున్నా నాకేమీ పని లేదు, లైఫ్ బోర్ కొడుతుందని. కాని నిన్నటి నుంచి నేను చాల బిజి. కారణం ఏంటో తెలుసా? చాల మంది తెలుగు బ్లగర్స్ వున్నారని తెలుసుకుని, వాళ్ళ బ్లాగులు చదవటం మొదలుపెట్టా. ఇంకా చదువుతూనే వున్నా.

అసలు నాకు తెలుగు ఎందుకు చదవాలని అనిపించింది అంటే, చాలా రోజుల తర్వాత నేను తెలుగులో ఉత్తరం వ్రాయల్సి వచ్చింది, మా మామయ్యకు. ఉత్తరమే ఎందుకు, ఫోన్ చెయ్యోచ్చుగా అనుకుంటున్నరా? ఒక చెక్కు పంపాల్సివచ్చింది. ఉత్త చెక్కును కవర్ లొ పెట్టి పంపలేముగా, దాంతో ఏవో కొన్ని మాటలు రాద్దామని పేపర్ తీసుకున్నా. అంతే! నాకు తెలుగు రాయటం రావట్లేదు. ఎంత ట్రై చేసినా ఇంగ్లీషులోనే పదాలు వస్తున్నాయి. చివరికి నాలుగు ముక్కలు రాసి పోస్ట్ చేసా. ఇంక అప్పుడు నిర్ణయింఛుకున్నా నేను నా తెలుగు ప్రతిభను తిరిగి తెచ్చుకోవాలని. (నా తెలుగు రైటింగ్ చాలా బాగుండేది, కాని ఈ ఇంజనీరింగ్ చదువులు చదివి అంతా మర్చిపోయా.)

వర్తమానంలోకి వస్తే, ఇప్పటి వరకు నేను కొన్ని తెలుగు బ్లాగులు మాత్రమే చదివాను. వాటిలో శోధన, చదువరి, గడ్డిపూలు, స్వాతి కుమారి, క్రిష్ణదేవరాయలు, స్నేహమా, మరి ముఖ్యంగా వీవెన్. ఇంకా నేను చదవ వలసిన బ్లాగులు చాలా వున్నై. వాటిని రేపటికి వాయిదా వేస్తూ....

- ఉమా..

Wednesday, November 01, 2006

మా తెలుగు తల్లికి మల్లెపూదండ (Maa Telugu Talli ki Mallepoodanda)


On the Occuaction of Andhra Rastra Avatarana Dinostavam!

Tuesday, October 31, 2006

**Casino Royale** - A Prequel , Reboot and Retcon


"Casino Royale" the name reflects the gambling game where gamblers earn more money fooling the players. Casino Royale is the latest Bond movie to be released on 17'Nov. Its being directed by Martin Campbell, who had directed the movies like "Golden Eye", "Vertical Limit", and "Mask of Zorro". Being a big fan of James Bond i am awaiting for this adventurous venture's release. This new venture is coming with lots of changes from the previous bond movies, and first of all new bond is introducing, Daniel Criag'. Looking at the posters im not able to digest Daniel Criag as James Bond. I still prefer to watch Peirce Brosnon as Bond even he is older.

My curiosity towards Bond movies thrown me to search for new information regarding the Casino Royale. I came to know many interesting points about this venture and may be it is the reason that Brosnon asked for more remuneration. The Casino Royale is the First ever novel of James Bond series written by Ian Flemming. Its going to show James bond differently from the previous sequel. Its a bit serious and non-comedic adaptation of Ian Flemings Story.
Title of this post reflects that its a prequel, reboot, and retcon of the Bond movies. Why it is a prequel is that the story will tell us the necissity of born of James Bond which was narrated by Ian Flemming. Its a Retcon (Retroactive Continuity), coz its going to show something different in JamesBond from the older sequel. And its a Reboot, since Pierce Brosnon was retired from Bond Character and New Bond, Daniel Criag, was adopted.
This movie is against terrorism and Criag is about to stop winning a bank in the Casino Royale game which supports the terrorist groups. Lets wait till Nov'17th to watch the new Bond and his (new)Bond girls.
Note: Eon Productions decided to take another Jame Bond venture with Daniel Criag. Could it be expected that Craig fits well into Bond character?

Sunday, October 15, 2006

State of Mind, an experience!

After a long gap of more than two months, i am back to blogging. This post is abt my experience of Soft skills session in our training schedule. I enjoyed this session more and particularly the games which we played individually and as a team learnt us many things which we were not aware of. This is what is terms in behavioural science 'hiding due to blindedness'. Many of us feel that a typical puzzle or game can not be solved by myself, without any others help. But we did came to experience physically as its only our perception of being tough. We played games like 'BrainLock', 'Gammat-Jammat', 'Ring Toss', etc.. But all these games are not only involving analytical thinking, but also requires technical fundas which we might have learnt in school days. Particularly when it comes to the BrainLock game, its too difficult to crack it, without the technical clue, the centrifugal force.
While playing these games, my state of mind is sometimes puzzy and sometimes i forcedly kept it to peaceful to solve the puzzle. But its founded that to solve any kind of problem, our state of mind must be peaceful, for getting the better and productive results.
I want to dwell more into this behavioral science to deal with large number of people. Shd anyone help me out there any kind of books or practices u came across?

Thursday, July 27, 2006

Destination@home

I am presently at my home, enjoying home food. I completely switched on to home food within one day, after 7 months long gap, thank god. My stay will be for 2 weeks and 'll left to Pune to join in Amdocs. I need to get police clearance, get ICNR stamp on my passport, and have to meet all my old friends.

Friday, July 21, 2006

I am Graduated

Yeah!
I am graduated, at last!. I successfully finished my Masters in Software Engineering. Now i can sleep more than 6hrs a day. Its time to get out of all the tensions.
Thank god, and to my thesis supervisor, Prof. B. D. Chaudhary, without his help, i may not get degree with better satisfaction.
I have a strange feeling, but i dont know why it is so? Everyone have feel that they are leaving MNNIT, spending 2 yrs here, and when its time to leave, they are getting little bit senti. But i dont have such feelings, and that too im feeling very happy as a prisioner gets released (may be my comparision is not so effective).
My overall satisfaction is good. But only having a little bit angry on MNNIT, that no one recognize a graduate's worth, and even every one try to degrade their confidence level, only a few professors know how to extract the good output, upto their expectation, and my supervisor is one in that list.
But overall MNNIT is a good place, i learnt how to live, the infrastructure is good, need to be amended.

Friday, June 30, 2006

An excerpt from A Film by Aravind

కలయో మాయో నువు కలసిన ఈ పూట
వలపో గెలుపో ఇరు మనసుల ఈ ఆట
నీ చెలిమి నాకు కొత్త భాష నేర్పగ, ఊసులన్ని పెదవి చాటు చేరగ పాడిన ఈ పాట
తొలిప్రేమకే సరిలేదని, తొలిస్పర్శక ఎదురేదని చెబుతున్న ఈ మాట

On request from vikram i am editing the above master piece, i like it very much, in english:

kalayo mayo nuvu kalasina ee poota,
valapo gelupo iru manasula ee aata,
nee chelimi naku kotta bhasha naerpaga, oosulanni pedavi chatu cheraga paadina ee paata,
tholi premake sariledani, tholi sparsake eduraedani chebutunna ee maata!

vikram, hope u understand it.