当前位置:网站首页>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
边栏推荐
- 《Just because》阅读感受
- Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
- Official announcement! The golden decade of new programmers and developers was officially released
- Market Research - current situation and future development trend of environmental friendly fireworks Market
- Market Research - current situation and future development trend of marine clutch Market
- 关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
- Market Research - current market situation and future development trend of handheld wound imaging equipment
- From "bronze" to "King", there are three secrets of enterprise digitalization
- About test cases
- Market Research - current situation and future development trend of anterior cruciate ligament (ACL) reconstruction Market
猜你喜欢
Oriental Aesthetics and software design
Sql service intercepts string
kubernetes资源对象介绍及常用命令(四)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
Micro service gateway selection, please accept my knees!
Introduction to victoriametrics
Evolution of messaging and streaming systems under the native tide of open source cloud
sql service 截取字符串
Technical solution of vision and manipulator calibration system
Daily book CSO advanced road first exposed
随机推荐
地理探测器原理介绍
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
ServiceMesh主要解决的三大痛点
How do I access the kubernetes API?
《Just because》阅读感受
Pyqt picture decodes and encodes and loads pictures
Off chip ADC commissioning record
Technological Entrepreneurship: failure is not success, but reflection is
Pointer array parameter passing, pointer parameter passing
[shutter] shutter layout component (wrap component | expanded component)
[shutter] shutter gesture interaction (click event handling | click OnTap | double click | long press | click Cancel | press ontapdown | lift ontapup)
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
【剑指 Offer】56 - I. 数组中数字出现的次数
Market Research - current market situation and future development trend of night vision goggles for pilots
B.Odd Swap Sort(Codeforces Round #771 (Div. 2))
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
Etcd raft protocol
540. Single element in ordered array
[Jianzhi offer] 57 And are two numbers of S