向量载体存在哪些问题? [英] What are the Issues with a vector-of-vectors?

查看:75
本文介绍了向量载体存在哪些问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到vector -of- vector s在给定的2 nd 维度下是不好的,但是我找不到关于 http://www.stackoverflow.com .

I've read that a vector-of-vectors is bad given a fixed 2nd dimension, but I cannot find a clear explanation of the problems on http://www.stackoverflow.com.

有人可以解释为什么在单个vector上使用2D索引比在固定的2 nd 维度上使用vector -of- vector更好吗?

Could someone give an explanation of why using 2D indexing on a single vector is preferable to using a vector-of-vectors for a fixed 2nd dimension?

此外,我假设vector -of- vector s是具有2 nd 变量的2D数组的首选数据结构?如果有相反的证据,我很乐意看到.

Also, I'm assuming that a vector-of-vectors is the preferable data structure for a 2D array with a variable 2nd dimension? If there is any proof to the contrary I'd love to see that.

推荐答案

我将用一个简单的类比来回答.

I shall answer with a simple analogy.

在这两件事中,更好"通常是什么?

What is "better" in general out of the two things?

  1. 电话簿,其中每个条目都是一个代码,它是指您必须查找并阅读以发现某人电话号码的另一本书的代码
  2. 一本列出人们电话号码的电话簿

在计算机缓存中将所有数据保存在一个大blob中更简单,更明智,更容易.在内部带有 N 个向量的向量要复杂得多(请记住,每个向量都需要动态分配和大小管理操作!);一个向量就是一个向量您还没有将工作量乘以 N .

Keeping all your data in a single big blob is more simple, more sensible, and easier on your computer's cache. A vector with N vectors inside it is much more operationally complex (remember, each of those requires a dynamic allocation and size management operations!); one vector is, well, one vector. You haven't multiplied the workload by N.

唯一的缺点是要使用1D基础数据存储来模拟2D阵列访问,您需要编写一个Facade.幸运的是,这很容易.

The only downside really is that to simulate 2D array access with a 1D underlying data store, you need to write a facade. Fortunately, this is very easy.

现在是主观部分:总的来说,除非您真的很急并且您的代码质量并不特别重要,否则我认为这是值得的.

Now for the subjective part: on balance I'd say that it's worthwhile unless you're really in a rush and your code quality doesn't particularly matter.

这篇关于向量载体存在哪些问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆