Should I free 'buf' after assigning a dynamic char vector to it?
I cannot decide:
Code:vector<char> vec(dynamic size,'1'); char * buf = &vec.at(0); free (buf);
Should I free 'buf' after assigning a dynamic char vector to it?
I cannot decide:
Code:vector<char> vec(dynamic size,'1'); char * buf = &vec.at(0); free (buf);
Using Windows 10 with Code Blocks and MingW.
No. The memory you're pointing your buf pointer at was allocated by the std::vector object. std::vector was written to do its own memory management and thus will clean up after itself. Besides, in C++ if you have to allocate memory from the free store, you generally want to use new / new [] and delete / delete [] instead of malloc and free.
Great, thank you!
Using Windows 10 with Code Blocks and MingW.