结构数组的智能指针? [英] Smart pointer for arrays of structs?
问题描述
我有一些数据存储为普通的旧C结构。到目前为止,我已经在堆栈上有这些结构的数组,但由于堆栈溢出,我需要将这些结构移动到堆中。
我一直在尝试一些智能指针来帮助,但到目前为止,我一直在处理的
实现与[]运算符
有问题,因为它可以使用带有unsigned char的相同类时会发生冲突。
您对能够使用数组的智能指针有什么建议吗?
我需要类似的东西:
ptr =(new或malloc)MY_STRUCT [16];
ptr [i] .member
谢谢。
- Henrik
Henrik Goldman写道:
我有一些数据存储为普通的旧C结构。到目前为止,我已经在堆栈上有这些结构的数组,但由于堆栈溢出,我需要将这些结构移动到堆中。
我一直在尝试一些智能指针来帮助,但到目前为止,我一直在处理的
实现与[]运算符
有问题,因为它可以使用带有unsigned char的相同类时会发生冲突。
您对能够使用数组的智能指针有什么建议吗?
我需要类似的东西:
ptr =(new或malloc)MY_STRUCT [16];
ptr [i] .member
std :: vector有什么问题?
>
std :: vector有什么问题?
我忘了提到要求从外部C函数访问数据需要
。因此,它需要像普通数组一样序列化。
- Henrik
< blockquote>" Henrik Goldman" < he ************ @ mail.tele.dkwrote in message
news:45 **************** *****@dread11.news.tele.dk。 ..
std :: vector有什么问题?
我忘了提到需要从外部C函数访问数据需要
。因此,它需要像普通数组一样序列化。
- Henrik
std :: vector符合这个要求。
http://www.parashift.com/c++-faq-lit....html#faq-34.3
vector存储它的内存连续的
Hi,
I have some data which is stored as plain old C structures. Until now I''ve
had arrays of these structs on stack but due to stack overrun I need to move
these to heap.
I''ve been trying out some smart pointers to help but so far the
implementation I''ve been dealing with has had problems with [] operator
since it could conflict when using the same class with "unsigned char".
Do you have any recommendations for smart pointers able to work with arrays?
I would need something like:
ptr = (new or malloc) MY_STRUCT [16];
ptr[i].member
Thanks.
-- Henrik
Henrik Goldman wrote:Hi,
I have some data which is stored as plain old C structures. Until now I''ve
had arrays of these structs on stack but due to stack overrun I need to move
these to heap.
I''ve been trying out some smart pointers to help but so far the
implementation I''ve been dealing with has had problems with [] operator
since it could conflict when using the same class with "unsigned char".
Do you have any recommendations for smart pointers able to work with arrays?
I would need something like:
ptr = (new or malloc) MY_STRUCT [16];
ptr[i].member
What is wrong with std::vector ?
>What is wrong with std::vector ?I forgot to mention that it''s a requirement that the data needs to be
accessible from external C functions. For this reason it needs to be
serialized just like an ordinary array.
-- Henrik
"Henrik Goldman" <he************@mail.tele.dkwrote in message
news:45*********************@dread11.news.tele.dk. ..
What is wrong with std::vector ?
I forgot to mention that it''s a requirement that the data needs to be
accessible from external C functions. For this reason it needs to be
serialized just like an ordinary array.
-- Henrikstd::vector fits the bill for that.
http://www.parashift.com/c++-faq-lit....html#faq-34.3
vector stores it''s memory contiguous
这篇关于结构数组的智能指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!