0

How do I keep from wasting allocated memory?

I figured the basic code out but not sure how to refine it. https://code.sololearn.com/c05eQhmuY9vK/?ref=app

31st Dec 2017, 12:23 AM
emmey
emmey - avatar
9 Answers
+ 11
use vector?
31st Dec 2017, 12:33 AM
jay
jay - avatar
+ 9
I would just use push_back() for each item for now. Vectors resize dynamically when ever new data is added. You can use reserve [vector.reserve(size_t)] to make the vector array a certain size to increase the speed of adding items, but generally the speed gained is negligible.
31st Dec 2017, 2:00 AM
jay
jay - avatar
+ 9
also try out <string> instead of char arrays. :)
31st Dec 2017, 2:05 AM
jay
jay - avatar
+ 8
They are super easy. Think dynamically sized arrays.
31st Dec 2017, 1:07 AM
jay
jay - avatar
+ 8
https://code.sololearn.com/c4XHX17H4Xvt/?ref=app have a look at this code example. It may help
31st Dec 2017, 2:01 AM
jay
jay - avatar
+ 1
I will mess with pointers. Have not learned alot about vectors yet. I understand what they are but not sure of working with them yet.
31st Dec 2017, 12:36 AM
emmey
emmey - avatar
+ 1
@Jay. I am reading this. Is the shrink to fit member function what we qould use? Or am I jumping to far in.
31st Dec 2017, 1:32 AM
emmey
emmey - avatar