Files
XCSDD/docs/api/containers/array/size.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

961 B
Raw Blame History

Array::Size() / Capacity() / Empty()

size_t Size() const;
size_t Capacity() const;
bool Empty() const;

获取数组的尺寸信息。

Size() 返回数组中的实际元素数量。

Capacity() 返回底层内存缓冲区能容纳的元素数量,不一定等于 Size()

Empty() 返回数组是否为空(Size() == 0)。等价于 Size() == 0,但更语义化。

返回:

  • Size() - 元素数量
  • Capacity() - 底层缓冲区容量
  • Empty() - 是否为空

复杂度: O(1)

示例:

Containers::Array<int> arr;

arr.Size();      // 0
arr.Capacity();  // 0
arr.Empty();     // true

arr.PushBack(1);
arr.PushBack(2);

arr.Size();      // 2
arr.Capacity();  // 4自动扩容
arr.Empty();     // false

arr.Reserve(100);
arr.Size();      // 2元素数量不变
arr.Capacity();  // 100容量增加

相关文档