Files
XCEngine/docs/api/containers/array/resize.md
ssdfasd dc850d7739 docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
  - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
  - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
  - core: 修复 types 链接错误
  - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
  - memory: 修复头文件路径, malloc vs operator new, 新增方法文档
  - resources: 修复 Shader/Texture 链接错误
  - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00

47 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Array::Resize()
```cpp
void Resize(size_t newSize);
void Resize(size_t newSize, const T& value);
```
调整数组大小。
**Resize(newSize)**
- 如果 `newSize > Size()`:在末尾构造 `newSize - Size()` 个默认构造的元素
- 如果 `newSize < Size()`:销毁末尾多出的元素
- 如果 `newSize == Size()`:什么都不做
**Resize(newSize, value)**
- 行为同上述,但扩展时使用 `value` 拷贝构造新元素,而非默认构造
**参数:**
- `newSize` - 新的元素数量
- `value` - 扩展时用作填充值的元素
**复杂度:** O(n),涉及元素构造/析构和可能的内存重新分配
**线程安全:** ❌ 操作期间不可并发访问
**示例:**
```cpp
Containers::Array<int> arr = {1, 2, 3};
// 扩展到 5 个元素,新元素默认构造为 0
arr.Resize(5);
// arr = {1, 2, 3, 0, 0}
// 缩减到 2 个元素
arr.Resize(2);
// arr = {1, 2}
// 扩展到 4 个,填充为 -1
arr.Resize(4, -1);
// arr = {1, 2, -1, -1}
```
## 相关文档
- [Array 总览](array.md) - 返回类总览