Search Results

Search found 2 results on 1 pages for 'nicksoft'.

Page 1/1 | 1 

  • c++ std::ostringstream vs std::string::append

    - by NickSoft
    In all examples that use some kind of buffering I see they use stream instead of string. How is std::ostringstream and << operator different than using string.append. Which one is faster and which one uses less resourses (memory). One difference I know is that you can output different types into output stream (like integer) rather than the limited types that string::append accepts. Here is an example: std::ostringstream os; os << "Content-Type: " << contentType << ";charset=" << charset << "\r\n"; std::string header = os.str(); vs std::string header("Content-Type: "); header.append(contentType); header.append(";charset="); header.append(charset); header.append("\r\n"); Obviously using stream is shorter, but I think append returns reference to the string so it can be written like this: std::string header("Content-Type: "); header.append(contentType) .append(";charset=") .append(charset) .append("\r\n"); And with output stream you can do: std::string content; ... os << "Content-Length: " << content.length() << "\r\n"; But what about memory usage and speed? Especially when used in a big loop. Update: To be more clear the question is: Which one should I use and why? Is there situations when one is preferred or the other? For performance and memory ... well I think benchmark is the only way since every implementation could be different. Update 2: Well I don't get clear idea what should I use from the answers which means that any of them will do the job, plus vector. Cubbi did nice benchmark with the addition of Dietmar Kühl that the biggest difference is construction of those objects. If you are looking for an answer you should check that too. I'll wait a bit more for other answers (look previous update) and if I don't get one I think I'll accept Tolga's answer because his suggestion to use vector is already done before which means vector should be less resource hungry.

    Read the article

  • List tags with commits in the same format like git branch -v

    - by NickSoft
    Hi I would like to list tags like it's listed by: # git branch -v * devel e7f5e36 firxed bugs master 63e9c56 remove unused code without the * (you can't checkout tag). It would be good to have an option to list full or short SHA1. A bash script is also fine, but it would be nice to use git commands more and shell scripting less. I've read this question Git - how to tell which commit a tag points to and it helped me, but it's not all I want. Edit: I didn't know that annotated tags had SHA1. I wanted SHA1 of commits that tag points to, not the tags themselfs.

    Read the article

1