<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000066">
I understand the appeal to not allow objects to be allocated on the
stack. I'm most comfortable just using something like the following:<br>
Image *img = new Image();<br>
delete img;<br>
<br>
Will it be possible to use the "Image *img = reader.GetImage()" syntax
in gdcm from now on?<br>
<br>
I don't quite understand how to use the smartpointer in a loop
though... I have a list of files, and I need to do some operation on
all of them, so I would do something like the following:<br>
<br>
for (i=0;i<numfiles;i++) {<br>
/* open the dicom file */<br>
reader.SetFileName(filepath);<br>
if (!reader.Read()) {<br>
SetError(msg.Format("Dicomfile '%s' not readable -
LoadFile->LoadDicomFilelist()",filepath.c_str()));<br>
return 0;<br>
}<br>
image = reader.GetImage();<br>
<br>
/* get the image data... */<br>
imageDataSize = image.GetBufferLength();<br>
tmpImageData = new unsigned char[imageDataSize];<br>
image.GetBuffer((char*)tmpImageData);<br>
<br>
... etc ...<br>
}<br>
<br>
How would I do the above with a smartpointer?<br>
-Greg<br>
ps - I keep posting to the dcmlib list because all my posts to the
gdcm2 list bounce back to me, even though I'm signed up for the list.<br>
<br>
<br>
<br>
Mathieu Malaterre wrote:
<blockquote
cite="mid:bf0c3b3f0808301603m7d1c322ajdfc318d0f78f9884@mail.gmail.com"
type="cite">
<pre wrap="">The real issue is the well known problem of ownership in C++. If you
know what you are doing and would like a copy of the image (shallow
copy of the image), then the correct syntax is:
const Image& img = reader.GetImage();
SmartPointer<Image> copy = img;
When copy will go out of scope it will get deleted. The designed of
the smart pointer was largely inspired by the one in ITK, except that
*everything* in ITK derive from a common Object parent class. So code
are very consistent and people just copy everything aruond using smart
pointer. I have designed this dual syntax in GDCM, where some object
can be allocated on the stack, while the one designed to being used
via the SmartPointer implementation are not.
I either need to *seriously* update the documentation, and/or make
sure that no derive class from Object can be allocated on the stack.
Sorry for trouble.
-Mathieu
On Sat, Aug 30, 2008 at 1:58 PM, Greg Book <a class="moz-txt-link-rfc2396E" href="mailto:gbook@gbook.org"><gbook@gbook.org></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I encountered the exact same problem. I used "const Image& img =
reader.GetImage()" but... I need to load files in a loop and I can't modify
a const once its created. Any way around this?
Thanks,
Greg
Mathieu Malaterre wrote:
Oooops
On Wed, Aug 27, 2008 at 7:11 PM, Matthias Sweertvaegher
<a class="moz-txt-link-rfc2396E" href="mailto:matthias.sweertvaegher@uz.kuleuven.ac.be"><matthias.sweertvaegher@uz.kuleuven.ac.be></a> wrote:
Image img = imgReader.GetImage();
Nope, in fact that is the line that is causing the crash sorry for the
noise. Please replace for now with:
const Image& img = imgReader.GetImage();
And please, fill in a bug report.
Thanks,
_______________________________________________
Dcmlib mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Dcmlib@creatis.insa-lyon.fr">Dcmlib@creatis.insa-lyon.fr</a>
<a class="moz-txt-link-freetext" href="http://www.creatis.insa-lyon.fr/mailman/listinfo/dcmlib">http://www.creatis.insa-lyon.fr/mailman/listinfo/dcmlib</a>
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>