在单服务器多个客户端中使用的最佳数据结构 [英] Best Data structure to use in single server multiple clients
本文介绍了在单服务器多个客户端中使用的最佳数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
定义一个数据结构,它将所有用户及其详细信息保存在服务器中
注意:不应利用数据库.
Define a data structure which will hold all the users and their details in server
Note: Should not make use of database.
推荐答案
首先请问问您这些问题的人:
"Oi,讲师!为什么要使用数据结构而不是类?为什么当我们应该讨论行为时我们为什么要讨论数据?"
然后,当您完成该操作后,就可以得出客户服务器系统的用户"期望的行为,例如:
-给定提供的用户名,盐和密码哈希,它们是否经过身份验证?
-给定资源标识符,是否允许他们访问该资源?
-如果可以使用I/O的方式,他们可以自行编辑
当您完成了很多工作(这些描述为下一阶段的单元测试奠定了良好的基础)时,您可以:
-确定需要维护哪些数据以支持行为
-实现所需的行为和其他C ++工具
最后:
-如果您想要一种可以容纳所有用户所有内容的东西,请根据您的性能要求选择标准的库集合类(或仅使用std :: vector),并在其中创建该类的对象.
First off ask whoever asked you these questions:
"Oi, lecturer! Why a data structure and not a class? And why are we talking about data when we should be talking about behaviours?"
Then when you''ve done that work out what behaviours you''d expect from a "user" of a client server system, e.g:
- given a supplied user name, salt and password hash, are they authenticated?
- given a resource identifier are they allowed to access that resource?
- they can edit themselves if given a means of I/O
When you''ve done that lot (and those descriptions make a great basis for unit tests in the next phase) you can:
- work out what data you need to maintain to support the behaviours
- implement the behaviours and other C++ paraphernalia you need
Finally:
- As you want something that''ll hold everything about all users choose a standard library collection class according you performance requirements (or just use std::vector) and pile objects of the class you create in it.
我怀疑您的讲师正在寻找的答案是服务器应将当前连接的多个客户端作为链接列表进行维护.
这是因为客户端可以随时随地从任何位置消失/断开连接,并且您只想简单地删除客户端而不复制内存,并且要尽可能快.请注意,这将会发生很多.
您可以使用其他集合类(例如数组),但在速度方面效率不高.
I suspect the answer your lecturer is looking for is that the server should maintain currently connected multiple clients as a linked list.
This is because a client can disappear/disconnect at any time, from any position, and you want to simply remove the client without copying memory and as quickly as possible. And note that this will be happening a lot.
You could use other collection classes such as arrays but it would not be as effiicient in terms of speed.
这篇关于在单服务器多个客户端中使用的最佳数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文