So I want to have a buffer with an array of structs like this:
EventItem
{
tag; // some string or array of characters to describe the value;
value; // some integer or something
}
The value can be anything like int32. What I am concerned about is the tag. If I have an array of these objects, and I make the tag a string, what happens if the user inputs an EventItem into this buffer that has a long tag? Will that cause the buffer or parts of it to be copied to somewhere else in memory to hold this bigger EventItem (bigger because of this long string)?
Would it be better for me to limit the tag by just using a fixed amount of character by using an array instead of a string?
Obviously I don’t know exactly what I’m talking about, but I don’t know how the buffer can be created with the right amount of contiguous space without knowing the size of the EventItems in advance.
Could someone explain how this situation would go down for me?
Thanks very much in advance!
What you want is a
std::string.Not only because its c++ and not c, but also because operating on
std::strings is much easier than onchar[].Also, the construction of your struct might be easier and more straightforward as well, avoiding copy of
char[]Not clear (IMO), but im leaned towards the “no, and dont worry about it”. The only way that could happen would be that the buffer crosses a page boundary (assuming paged memory here). Well, if it happens, it happens. The miracle of virtual memory will take care of it.
Let
std::vectortake care of that. Of course, situations may arise always where contiguous space may not be available. Why are you so worried. Can you explain to us the situation where this would be a problem?