[Insight-users] array of smart pointers

Kevin H. Hobbs hobbsk at ohiou.edu
Fri Oct 16 05:22:29 EDT 2009


On 10/15/2009 11:41 PM, Xiaofeng Z wrote:
> Did you initialized the allocated memory?

I thought FloatImageType::New(); was supposed to do that.

>   Besides, unless you know the inner details of the smarter pointer,
> you don't really know how to initialize the memory.
>

Clearly I do not know how to initialize the memory.

Clearly FloatImageType::New(); does not completely set everything in a
block of memory the size of a FloatImageType::Pointer.

I guess this fits with this newfangled C++ idea of a constructor,
declaring a FloatImageType::Pointer will lead to an object that is NOT
filled with junk, but filled with some defined values that say "I'm an
empty image smart pointer"

Anyway just replacing my malloc lines with  std::vector<
FloatImageType::Pointer > recv_images( mpi_size ); worked just fine.

> --------------------------------------------------
> From: "Kevin H. Hobbs" <hobbsk at ohiou.edu>
> Sent: Thursday, October 15, 2009 1:54 PM
> To: "Insight Users List" <insight-users at itk.org>
> Subject: [Insight-users] array of smart pointers
>
>> My (unfinished and attached) program is segfaulting at line 192 where I
>> create a new image smart pointer and assign it to an element of an array
>> of smart pointers.
>>
>> recv_images[ split ] = FloatImageType::New();
>>
>> I got the array of smart pointers from malloc with :
>>
>> FloatImageType::Pointer * recv_images =
>>     (FloatImageType::Pointer *) malloc(
>>       mpi_size * sizeof( FloatImageType::Pointer ));
>>
>> I know this isn't very C++ish but shouldn't it work?
>>
>
>
>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091016/58dc77bc/attachment.pgp>


More information about the Insight-users mailing list