简体   繁体   English

C ++动态数组构造函数

[英]C++ dynamic array constructor

I have been asked to implement a dynamic array in C++. 我被要求在C ++中实现动态数组。 For the constructor we are to "allocate default buffer or wait for first insert". 对于构造函数,我们将“分配默认缓冲区或等待第一次插入”。

I do not understand what a default buffer is and why it would it speed up memory operations. 我不了解默认缓冲区是什么以及为什么它将加速内存操作。 Also, what does it mean when it says wait for the first insert? 另外,当它说等待第一次插入时,它是什么意思?

  1. a default buffer, would mean a default size that the array has from start when you create the instance of your dynamic array, then when the array increases you do not need to increase the buffer until that space has run out. 默认缓冲区表示创建动态数组实例时数组从开始就具有的默认大小,然后当数组增加时,直到该空间用完时才需要增加缓冲区。

  2. having no default buffer but once the user inserts the first element into the array, then you allocate memory for one element (or multiple elements in a buffer). 没有默认缓冲区,但是一旦用户将第一个元素插入数组,就可以为一个元素(或缓冲区中的多个元素)分配内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM