空向量是其结构的大小吗?

编程入门 行业动态 更新时间:2024-10-17 17:22:01
本文介绍了空向量是其结构的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一个这样的结构:

Say I have a struct like this:

struct vertexNodeInfo { unsigned char level; int node; double leaf; };

如果我当时有这个:

vector<vertexNodeInfo> node;

在任何 push_back 之前,空向量有多大(内存方面,不是 .size)?它是否与 vector<int> 的大小(同样,在内存方面)完全相同?节点;?

How big (memory-wise, not .size) would the empty vector be, before any push_back? Would it be exactly the same size (again, in terms of memory) as vector<int> node;?

推荐答案

没有要求.更重要的是,这是一个表述不佳的问题.

There's no requirement. Even more, it's a poorly formulated question.

向量的 .size 将是 0,因为它没有元素.

The .size of the vector would be 0, because it has no elements.

sizeof 不会影响元素的数量,并且通常足够大以包含一两个指向该类型的指针(它们本身的大小可能会有所不同,因此不能保证 sizeof(vector) 和 sizeof(vector) 相等),大小和容量.

The sizeof isn't affected the number of elements, and is typically large enough to contain one or two of pointers to the type (which can vary in size themselves, so there's no guarantee the sizeof(vector<vertexNodeInfo>) and sizeof(vector<int>) are equal), the size and capacity.

更多推荐

空向量是其结构的大小吗?

本文发布于:2023-11-02 14:19:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552637.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   大小   结构

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!