Feels like this could be a lot simpler.
For example:
1 2 3 4 5
|
struct requestMessage
{
string entireMessage;
int locationOfBodyStart; // the element in the above string where the body begins
};
|
stored in a
map<string, requestMessage>
. Done. The string, and the information about where in that string the body begins, stored safely together. No weird turning memory addresses into strings, and hoping that the memory never changes.
If you store a pointer to part of a string, then you have to make sure that string still exists in the exact same place in memory for as long as you have that pointer. Assuming that the strings inside a map will never ever move is risky; you have no such guarantee. Were you actually storing the location of the body of the message inside the map, or were you getting a memory address inside a string that you were discarding anyway?
Storing memory addresses into these strings (and even worse, storing those memory address themselves AS strings), put simply, is dangerous and unreliable. Inventive, sure, but a complicated and dangerous solution to a simple problem. Added problem; if you're storing the strings in a map, then you'd need to put the string in the map, and then look a the string inside the map and get the memory address of interest to turn into another string. What a pain that is. And still weird. Why store it as a string when you could store it as a char*? You say because you have a map of strings, but you could have changed it to a map of char*.