Original Post
In my code i have a whole bunch of the following uses of std::stringstream to convert data to stings and then send the string data, so some particular function that requires a string or C-string. Such as the following, every frame, a new std::stringstream is created, the precision set, some data passed into it, and then the Cstring pointer is sent to another function, and this std::stringstream is lost when the scope ends. But this is done every frame, and is done a bunch of times for all the other win32 dialog edit boxes that i fill with data, so im wondering which is better, the first example or the second, by where in the second, the same std::stringstream, is used, its just cleared.
//pixels
std::stringstream MouseXPos2;
static std::string LastMouseXPos2;
MouseXPos2.precision(2);
MouseXPos2 << std::fixed << MousePosition.x;
if(MouseXPos2.str() != LastMouseXPos2){
SendMessage(GetDlgItem(HwndSide,IDC_EDIT_GRID_POINTER_X_PIXELS), WM_SETTEXT, 0, (LPARAM) MouseXPos2.str().c_str());
LastMouseXPos2 = MouseXPos2.str();
}
std::stringstream MouseYPos2;
static std::string LastMouseYPos2;
MouseYPos2.precision(2);
MouseYPos2 << std::fixed << MousePosition.y;
if(MouseYPos2.str() != LastMouseYPos2){
SendMessage(GetDlgItem(HwndSide,IDC_EDIT_GRID_POINTER_Y_PIXELS), WM_SETTEXT, 0, (LPARAM) MouseYPos2.str().c_str());
LastMouseYPos2 = MouseYPos2.str();
}
std::stringstream MousePos;
static std::string LastMouseXPos, LastMouseYPos;
MousePos.precision(2);
MousePos << std::fixed << MousePosition.x;
if(MousePos.str() != LastMouseXPos){
SendMessage(GetDlgItem(HwndSide,IDC_EDIT_GRID_POINTER_X_PIXELS), WM_SETTEXT, 0, (LPARAM) MousePos.str().c_str());
LastMouseXPos = MousePos.str();
}
MousePos.str("");
MousePos << std::fixed << MousePosition.y;
if(MousePos.str() != LastMouseYPos){
SendMessage(GetDlgItem(HwndSide,IDC_EDIT_GRID_POINTER_Y_PIXELS), WM_SETTEXT, 0, (LPARAM) MousePos.str().c_str());
LastMouseYPos = MousePos.str();
}