Pages

Wednesday, September 14, 2011

dynamic memory allocation without using heap

Mind Mapping :
Operator Overloading, Thinking in C++ Vol 1( Bruce Eckel) ->  doubts in Constant functions ->
browser -> times of india -> early enterpeuner ->
www.sourcebits.com (MBBS, MD tunred into a techie, started as one man company and now a leading mobile app firms with one of its app went to top 3 in 3 days), Impressed by the graphic design, I gave a pause, world is progressing in a accelerated way and i m shitting here on Operator Overloading.

Before turning page in Ops Overloading, I first googled to see if c++ still in the market compared the new up coming technologies. There I found c++ recently updated it self this month Sept, 2011. first look link Under division constant expression, I figured out introduction of new keyword constexpr.


Wiki started as
int get_five() {return 5;}
 
int some_value[get_five() + 7]; //create an array of 12 integers. Illegal C++


and c++ version 11 has a solution


constexpr int get_five() {return 5;}


int some_value[get_five() + 7];


As per my understanding after spending 15 minutes to this section I realized similar things can be done using const keyword. Which in turn allowed me to do dynamic memory allocation without using malloc.


const int getSize(int i){return i;}


int main(int argc, char ** argv)
{
int a[ 1 + getSize( atoi(argv[1]) ) ];
cout<
return 0;
}


I was amazed.

No comments:

Post a Comment