How to allocate vector on heap for short string?
Hi My base understanding is that stack capacity is very small compared to heap capacity. When I am doing allocation of millions of data on vector, I am facing bad allocation failure. Refer code snippet below : 1. demoInts alllcates three int on stack and no heap allocation. 2. Refer code related to demo vector int (): When I am doing allocation for vector<int> , all int are allocated on heap. Due to this, I am not facing any bad allocation issue for vector<int> with millions of data pushed to vector 3. demostring alllcates three strings... One is large to overcome small sting optimization and gets allocated on heap. Rest 2 (s1 and S2) are small strings and gets on stack. 4. Refer code related to demo vector string (): When I am doing allocation for vector<string> , all the strings are not allocated on heap unlike vector<int>. It follows criteria of small string optimization My concern is this. vector<string> with million of small string does all allocation on stack which results into bad alloc