Re: How to make whole container(STL) to create in heap
"sandeep" <sandeep.k@incore.in> writes:
When we use STL which memory space it will use whither it is stack
or heap or data segment
How to make STL to create in heap?
How to make whole container to create in heap?
I think container uses stack is it correct ?
The object representing the container is wherever you place it. If
it's a local variable, then it's on the stack; if you create it
dynamically, it will be on the heap; and if it is defined at namespace
level or as a static data member, it will be somewhere else.
Where the container object places its internal data (e.g. its
elements) is determined by the allocator the container template is
instantiated with. The default allocator will place the internal data
on the heap.
I am using double linked list so in place of it I want to use STL
#include<stdio.h>
#include<iostream>
#include<vector>
You are mixing header generations here. Consistently #including
new-style headers is likely to lead to more predictible results.
using namespace std;
void fun();
void fun1();
vector<int> root;// I want to create this in heap
root is defined at namespace level; this means that it is not on the
heap. Since the default allocator is used, the array containing root's
elements will be on the heap, though.
If you want the vector object to be on the heap, you have to create it
with a new expression.
void main()
The return type of main() has to be int.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]