if i want an array of 10000 ints and i just nned to use it like array only (not the functions which vector have seprately from array), then i make an array int a[10000] and vector<int>a(10000); then memory allocation time will be different for them ? if yes, then please tell why ? thanks in advance.
nitin1
15
Master Poster
Recommended Answers
Jump to PostThe vector will be slightly larger for the class's other data members. But the array of integers will be the same size. If you don't need the methods of a vector them use a normal array.
Jump to Postwrite this program to find out how large the vector class is
#include <vector> #include <iostream> int main() { std::cout << "sizeof(vector) = " << sizeof(std::vectgor)) << '\n' }
Jump to PostThe difference in total memory used between a vector or an array is going to be negligible (probably only one pointer and two integers).
The use of a vector is going to take a bit more time to allocate the memory because it must ask the heap to allocate a …
All 9 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
nitin1
15
Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
nitin1
15
Master Poster
ravenous
266
Posting Pro in Training
nitin1
15
Master Poster
Lucaci Andrew
140
Za s|n
ravenous
266
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.