Friday, August 24, 2012

Visual Studio 2010 C++ set iterator issue | Set data structure in VS2010 - Part II

In the first part of the post we have explained the basics of set iterator & the issue we might face with set iterator in Visual Studio 2010. Now We should focus on the solutions for this kind issues with the bit complex coding like usage with classes. Anyhow it is better to catch up with simple things first then we can dig the things well later.

Let see what make our program  main2.cpp to break  (in last post's)

Problematic Main.cpp

#include <cstdlib>
#include <iostream>
#include <set>

using namespace std;
int main()
{
set<int> setInt;

for(int i=0; i<5; ++i)
 setInt.insert(i);

 for(set<int>::iterator iItr=setInt.begin(); iItr!=setInt.end(); iItr++)
 {
  if((*iItr) == 2)
   setInt.erase(iItr);
 }

 system("pause");
 return 0;
}

Here this code segment try to delete the element from the Integer Set which have the value "2". It will successfully delete the element but just after the deletion the setInt container's order gets affected, iterator iItr is no longer valid for accessing the elements. But iteration process keeps running. It is unnecessary & not acceptable in Visual Studio 2010. So It may link with the arbitrary location and finally give unhandled exception : Access violation run time error.


We can get rid off this issue through the small trick. We know that deletion happens properly that is why Set container is getting affected and it given crashes since we are iterating again.  Therefore if we stop the latter part everything will go in our way. Only one line of shit needed to throw this F__ away from us. When the particular element is found, it gets removed from the setInt. Once we delete the entity, we should come out from the for loop. For this break will do the trick.

Working Code


for(set<int>::iterator iItr=setInt.begin(); iItr!=setInt.end(); iItr++)
{
if((*iItr) == 2)
{
setInt.erase(iItr); 
break;
}
}

This will work perfectly fine, You can ensure by iterating the values again


for(set<int>::iterator itr=setInt.begin();itr!=setInt.end();++itr)
cout<<"Iterator Values:"<<*itr<<endl;


Output

Iterator Values:0
Iterator Values:1
Iterator Values:3
Iterator Values:4

--------------------------------------------------------------------------------------

For Incoming searches
- unhandled exception : Access violation run time error.
- VS 2010 compilation errors
- Visual Studio 2010 Set run time crashing
- VS 2010 set data structure convention change
- VS 2010 set Iterator issue solving



Saturday, June 30, 2012

How to find the size of Dedicated Video Memory?

Most of us might have found difficulties to get to know the Dedicated Video Memory size in Laptops while buying. Many people have a thought like, it is not possible to find out without installing any external application and some people are referring to some other wrong ways. Here I show the straight forward way to find this.

1. Right click on your desktop. You will get a Popup Menu



2. Click it on Screen resolution in that Popup Menu

3. You will get Screen Resolution Window then click it on Advanced Settings option



4. Now you will get another Window where you can find the details.


The Above Laptop is having 1GB Dedicated Video Memory.  This is damn simple way and you don't need to rely on any other things. 
-------------------------------------------------------------------------------
For Incoming searches
- How to find Dedicated Video Memory?
- Laptop Dedicated VGA Memory
- Visual Studio 2010 Set run time crashing
- Size of Dedicated VGA Memory


Monday, March 26, 2012

Visual Studio 2010 C++ set iterator issue | Set data structure in VS2010 - Part I


You may have come across some issues with Visual Studio 2010 when  you use the set data structure in your C++ program. If you want to compile the existing codes with VS 2010 IDE it may not be compiled as you expected. Here i am going to address one of those issues & the way to sort out the problem in some extent.


Let we start with simple shit of coding, then in our next post we can further look into complex problems using user defined class.

main1.cpp

#include <cstdlib>
#include <iostream>
#include <set>


using namespace std;
int main()

set<int> setInt;


for(int i=0; i<5; ++i)
setInt.insert(i);

for(set<int>::iterator iItr=setInt.begin(); iItr!=setInt.end(); iItr++)
{
*iItr = 10;
}

system("pause");
return 0;
}



If you compile the above code in VS 2010 it would give the error message like this. [error C3892: 'iItr' : you cannot assign to a variable that is const] The reason for this, in VS2010 set iterators will be considered as const iterator though you use normal ::iterator or ::const_iterator. It doesn't matter what is the iterator type you use, at the end all will be fallen under the category of const. The elements in the set are treated as constant. you can not change the elements property using set::iterator. Actually this was possible in the Visual Studio 2008 & earlier versions.

The reason for this error is, in the set data structure elements are sorted in a particular order and allowed to have unique entries. So if we change the element's properties in the set, the ordering will get affected. All elements needs to re arranged. Therefore, it's a acceptable reason for having the iterators as const iterator. This const iterators simply don't allow us to change the elements in the container. (Obviously that is the const iterators role). 

Then You can ask, what is the hell of not enabling this feature in Visual Studio 2008 & earlier versions? What to do with it. Yes it is their mistake, it should have been done before that. But theoretically this standard came after the VS 2008. So we can not blame even Microsoft as well.

main2.cpp


#include <cstdlib>
#include <iostream>
#include <set>

using namespace std;
int main()
{
set<int> setInt;

for(int i=0; i<5; ++i)
 setInt.insert(i);


for(set<int>::iterator iItr=setInt.begin(); iItr!=setInt.end(); iItr++)
{
if((*iItr) == 2)
setInt.erase(iItr);
}
system("pause");
return 0;
}


If you compile this code segment it won't be giving errors in compiling but rather must give the crashing issue at the run time. Since you removed one element from the set container's order got affetcted , just after the erasing that iterator iItr is no longer valid for accessing the elements. It would link with the arbitrary location and finally give unhandled exception : Access violation run time error

Next post we will see the tricks to overcome this issue.

For Incoming searches
- error C3892:  you cannot assign to a variable that is const
- VS 2010 compilation errors
- Visual Studio 2010 Set run time crashing
- VS 2010 set data structure convention change

Sunday, February 19, 2012

THALA Ajith's BILLA-II Unofficial Stills

The following stills/images got leaked unofficially in nets before Billa-II team release to Media. So this post just include those new stills on to this page that's it.















---------------------------------------------------------------------------------
For Incoming searches
- Ajith's Stills
- Ajith's Billa2
- Billa-II Unofficial Photos
- Billa-2 Unreleased Stills

Friday, February 17, 2012

My First Post

Hi Guys & Gals!

First up all, I would like to say "Thank you" for entering (?)  to this page. No matter whether anyone have come here or not, but saying thanks would be the ideal way to Welcome viewers to my blog. Ahhh my first task is over for this first post. :)



Of course, i am not a new lad to blog. I have been blogging for more than three years in my native language; proud to say it is "TAMIL" and somehow managed to get a place among the readers. Actually i am die heart Cricket & Cinema lover and used to write posts about these aspects in my tamil blog. Blog name is either Packet or Parcel. Don't know the exact meaning in English. In pure tamil it is pronounced as "Poddalam". Here we go, this is the link of my tamil blog. http://bit.ly/2ChErt


I planned to start a blog in English ages ago but didn't get proper time to sit down in a place and start the proceedings. Finally i did it now. Well i don't have a good knowledge or whatever in English. So i want to use this blog to improve my English writing skills. Hope, language wouldn't be a barrier for giving some facts and thoughts in my posts. Since i have been writing about Cricket and Cinema in my previous blog, this is allocated for some technical stuffs specially C++ stuffs. And occasionally i may write about some other things as well. Everything mostly depends on my future interest. :P See you all in the next post

Cheers Dudes!
||| CrazyBugger |||