当前位置:网站首页>U++ 学习笔记 ----松弛
U++ 学习笔记 ----松弛
2022-07-02 22:01:00 【是秃头的兔子呀】
由于默认构造的数组不分配内存,因此松弛度最初为零。GetSlack您可以使用该函数找出数组中有多少松弛。在容器重新分配之前,数组可以容纳的最大元素数可以通过Max函数获得。GetSlack相当于 和 之间的Max差Num:
TArray<int32> SlackArray;
// SlackArray.GetSlack() == 0
// SlackArray.Num() == 0
// SlackArray.Max() == 0
SlackArray.Add(1);
// SlackArray.GetSlack() == 3
// SlackArray.Num() == 1
// SlackArray.Max() == 4
SlackArray.Add(2);
SlackArray.Add(3);
SlackArray.Add(4);
SlackArray.Add(5);
// SlackArray.GetSlack() == 17
// SlackArray.Num() == 5
// SlackArray.Max() == 22以上为TArray的自动扩容
有一个Reset与 Empty 类似的函数,除了如果当前分配已经提供了请求的 slack,它不会释放内存。但是,如果请求的 slack 较大,它将分配更多内存:
SlackArray.Reset(0);
// SlackArray.GetSlack() == 3
// SlackArray.Num() == 0
// SlackArray.Max() == 3
SlackArray.Reset(10);
// SlackArray.GetSlack() == 10
// SlackArray.Num() == 0
// SlackArray.Max() == 10最后,您可以使用该函数删除所有 slack,该Shrink函数会将分配的大小调整为容纳当前元素所需的最小大小。Shrink对数组中的元素没有任何影响:
SlackArray.Add(5);
SlackArray.Add(10);
SlackArray.Add(15);
SlackArray.Add(20);
// SlackArray.GetSlack() == 6
// SlackArray.Num() == 4
// SlackArray.Max() == 10
SlackArray.Shrink();
// SlackArray.GetSlack() == 0
// SlackArray.Num() == 4
// SlackArray.Max() == 4边栏推荐
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- [zero foundation I] Navicat download link
- Using emqx cloud to realize one machine one secret verification of IOT devices
- Market Research - current situation and future development trend of sickle cell therapy Market
- Pointer - function pointer
- 100 important knowledge points that SQL must master: using cursors
- Kubernetes resource object introduction and common commands (4)
- GEE:(二)对影像进行重采样
- Market Research - current market situation and future development trend of aircraft front wheel steering system
- Market Research - current situation and future development trend of marine clutch Market
猜你喜欢

New feature of go1.18: trylock, which has been tossed n times

scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文

地理探测器原理介绍

An overview of the development of affective computing and understanding research

C language, to achieve three chess games

What is it that makes you tremble? Those without fans can learn

Daily book - low code you must understand in the era of digital transformation

Kubernetes resource object introduction and common commands (4)

How do I access the kubernetes API?

Oriental Aesthetics and software design
随机推荐
Sql service intercepts string
Market Research - current market situation and future development trend of aircraft audio control panel system
Market Research - current situation and future development trend of herringbone gear Market
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
Using emqx cloud to realize one machine one secret verification of IOT devices
C语言,实现三子棋小游戏
[zero foundation I] Navicat download link
Pointer array parameter passing, pointer parameter passing
[leetcode] sword finger offer 04 Search in two-dimensional array
Une semaine de vie
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
pyqt圖片解碼 編碼後加載圖片
Bridge emqx cloud data to AWS IOT through the public network
GEE:(二)对影像进行重采样
2019 Nanchang (relive the classic)
TinyMCE visual editor adds Baidu map plug-in
LandingSite eBand B1冒烟测试用例
APP页面分享口令Rails实现
[shutter] shutter resource file use (import resource pictures | use image resources)
Blue Bridge Cup Eliminate last one (bit operation, code completion)