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 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 …
Jump to PostIf the time taken to allocate a your vector/array is the main time cost in your program, then you're doing well!
In reality, I would almost always use
std::vector
You could end up saving space. For example, if you make an array of 10000int
s then as soon as the …
Jump to Postthat means having memory from heap is better than having memory from stack ?
No, they're different but niether is "better". Each is the right thing to do in different situations.
but i have felt that malloc function usually takes longer time so as to alocate memory.
…
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.