这会不会code让那些矢量一致? [英] Will this code make those vector aligned?

查看:387
本文介绍了这会不会code让那些矢量一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有:

vector<T *> vect;

我知道这不是明显的路要走,但我有一个API,它这样做,所以我不能决定使用矢量&lt; T&GT; ,而不是

所以,当我把对象是我做的:

so when I put object in it I do:

vect.push_back(new T);

这会不会code确保这个载体是<打击>对齐连续的,因为它是指针的载体?将这个容器中的经营者的行为决定的吗?

Will this code make sure that this vector is aligned contiguous since it's a vector of pointer? will this container decide of the behavior of the new operator ?

编辑: 将我还需要调用一个删除那些?

will I also need to call a delete on those ?

推荐答案

请问这个code确保该矢量一致,因为它是指针的载体?

不知道什么是对的对齐的你在这方面的认识,但情况类似,每个指针分配动态内存指针的数组。指针数组位于连续位置和他们每个人的指向位于所述堆某处的存储器。
如果指针元素的矢量相同的适用于这里。

Not sure what is your understanding of aligned in this context but the situation is similar to a array of pointers where each pointer is allocated dynamic memory. The array of pointers is located in contiguous locations and each of them points to a memory located somewhere on the heap.
The same applies here in case of vector of pointer elements.

请问我还需要调用一个删除那些?

Will I also need to call a delete on those ?

是的,你需要调用删除的各个元素明确。
标准库容器不参加的情况下元素是指针重新分配元素的记忆的责任。

Yes, You will need to call delete on each of those elements explicitly.
Standard Library containers do not take the responsibility of deallocating memory of elements in case the elements are pointers.

好读:
是否向量::擦除()销毁删除对象?

Good Read:
Does vector::erase() destroy the removed object?

这篇关于这会不会code让那些矢量一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆