I'm currently having the following data structure:
1 2 3 4 5 6
typedefstruct {
int a;
int b;
} S;
<vector <vector<S> > v;
Now I also have different pointers that can be set in connection with one instance of the above shown vector. Therefore I was attempting to work with a map:
map<p*, <vector<vector <S> >, vector<sI> > m;
However, it seems like it doesn't work that way. Therefore I tried the following:
I need two vectors as I do not want to define array-sizes without knowing how much I'll eventually need.
So I'll have one vector representing the clients which holds a vector representing data of those clients organised in structs.
a) Therefore I now have a vector for clients holding a vector for data which is organised in structs. That's this part:
1 2 3 4 5 6
typedefstruct {
int a;
int b;
} S;
<vector <vector<S> > v;
b) However, I am also having pointers representing instances of a certain script. I now have to combine those pointers with a) as I want to have the vectors organised with my instances. I thought I could do this with a map and later push_back new data somehow like that:
vec[pointer][client].push_back(s);
P.S: First day working with C++ - I work with Java and PHP more frequently.
What is the client? How is it identified? The phrase "Therefore I now have a vector for clients holding a vector for data which is organised in structs" is not clear,
Maybe you should keep the vector of data for a client inside the class defining the client as a private data-member.
Normally, I'd use a simple multi-dimensional array:
1 2 3 4 5 6
typedefstruct {
int a;
int b;
} data;
clients[10][data];
The problem is that I am not able to know how often data will be needed in that array - that's why I am now using vectors.
Clients are therefore just numerously defined.
You're right, I could create a class holding the clientID as an attribute and create for every new player a new object. Question is, is it more efficent to create hundrets of objects with one single vector in each of them or one vector holding another vector inside of it?
> Question is, is it more efficent to create hundrets of objects with one single vector in each of them
> or one vector holding another vector inside of it?
In either case, you would have hundreds of vectors.
Lookup on client id would be easy and efficient with a nested vector - assuming that client ids are consecutive numbers starting at zero, of course.
Question is, is it more efficent to create hundrets of objects with one single vector in each of them or one vector holding another vector inside of it?
Actually, the real question is:
Which is going to help you more, right now, to produce the program you want, running reliably:
1) Making your code clearer and easier for you to understand, debug, and maintain, by properly encapsulating your client data inside a Client class
2) Fretting about efficiency.
Lots of programmers waste a lot of time and energy worrying about efficiency, to very little benefit, and make their code much harder to get working properly in doing it.
Well, it's all not in English. Shall I re-install the whole program now to get errors in English? I also cannot translate it as I do not fully understand it.
Well, it's all not in English. Shall I re-install the whole program now to get errors in English? I also cannot translate it as I do not fully understand it.
If language is becoming a barrier to getting the help you're looking for, perhaps you'd be more able to get help from someone who speaks the same language as you?