1. "memory efficient"
"my texts contain 10k+ chars and I might need to do 1000+ links to single text, it won't be really memory efficient" - let's say you will have 1000 strings of length 10 000 characters, that's 10 mil bytes = ~9.54MB + assuming some little overhead, this definitely won't consume more than 10MB of memory
2. pros and cons
Of course you can working with these "links" in form of structures, just spend a while thinking about why you are doing it. What advantages will this approach have? If memory efficiency is the only reason why you would do that, you are most likely entering the dungeons of premature optimization.
3. "how to assign a pointer to part of the string"
std::string str = "My simple string";
Node n;
n.ptrToNodeStart = &str[3];
n.nodeLen = 6;
// n is expected to refer to string "simple" here
but actually it's not that simple. str is object with automatic storage duration, once the execution leaves this scope, the memory where string was stored is freed, i.e. you have problem 1: lifetime ... if your string is gone and you still keep your Nodes, these become nothing but a bunch of invalid / dangling pointers.
problem 2: Since there is no null-terminating character, you are unable to treat this pointer in Node as a string. If you are going to need it, you are most likely about to end up with C-style error-prone code that will be doing evil stuff like:
std::string tempStr(n.nodeLen + 1, '\0');
memcpy(&tempStr[0], n.ptrToNodeStart, n.nodeLen);
// yehey !!! I can finally use this annoying Node as a normal string now ....
or even worse:
char *buffer = new char[n.nodeLen + 1];
memcpy(buffer, n.ptrToNodeStart, n.nodeLen);
buffer[n.nodeLen] = '\0';
// using buffer here ...
delete[] buffer;
My advices:
- avoid using pointers if possible
- stick to neat objects from the standard library
- go for
std::string objects, std::vector<std::string> stringParts ...
use std::string::substr():
std::string str = "My simple string";
std::string part = str.substr(3,6);
// part holds string "simple" now