[Insight-developers] how to detect pixel allocation failure ?
Miller, James V (GE, Research)
millerjv at crd.ge.com
Wed Mar 15 16:50:50 EST 2006
In my experience, it is hard to know whether an allocation fails.
For instance, on multi-tiered memory systems like what SGI uses,
the system always says the allocation succeeds and assumes that
by the time you try to access the memory it will be available
(because you would have freed somethingelse). So a memory allocation
doesn't fail until you try to read/write to the memory.
That being said, if we can detect failure on some systems we should
try to report it. The problem then becomes: what do you do if an allocation
fails? How can ITK or the application recover?
Jim
-----Original Message-----
From: insight-developers-bounces+millerjv=crd.ge.com at itk.org
[mailto:insight-developers-bounces+millerjv=crd.ge.com at itk.org]On Behalf
Of Simon Warfield
Sent: Wednesday, March 15, 2006 12:10 PM
To: Insight-developers
Subject: [Insight-developers] how to detect pixel allocation failure ?
I have some code that runs fine on a 64 bit workstation but fails with a
segmentation fault on a 32 bit workstation.
It turns out this code is allocating a 4D image of size 256x256x40x208
pixels.
The code fails in a call to FillBuffer(0) when after a certain number of
pixels (*m_Buffer)[i] stops being a valid container.
> Size of the LargestPossibleRegion
> 256 256 46 208
> About to call W->FillBuffer(0)
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1208133952 (LWP 5008)]
> 0x080ea098 in itk::Image<double, 4u>::FillBuffer (this=0x981d730,
> value=@0xbfe998b8)
> at
> /opt/i386/pkgs/itk/2.4.1/gcc-release/include/InsightToolkit/Common/itkImage.txx:83
> 83 (*m_Buffer)[i] = value;
> (gdb) print i
> $1 = 90178047
The buffer is allocated through AllocateOutputs() which ultimately calls
itk::ValarrayImageContainer<TElementIdentifier, TElement>::Reserve()
It turns out that Reserve() is not guaranteed to allocate the pixels as
requested. The documentation says Reserve does the following:
> Tell the container to allocate enough memory to allow at least as many
> elements as the size given to be stored. This is NOT guaranteed to
> actually allocate any memory, but is useful if the implementation of
> the container allocates contiguous storage. Definition at line 112
> <http://www.itk.org/Doxygen/html/itkValarrayImageContainer_8h-source.html#l00112>
> of file itkValarrayImageContainer.h
> <http://www.itk.org/Doxygen/html/itkValarrayImageContainer_8h-source.html>.
The API for itk::Image->Allocate() is for Allocate() to return void,
whether or not allocate succeeds.
I wonder if it should instead return a boolean indicating success or
failure of the Allocate() operation ?
Is there some other means to determine if Allocate() was successful ?
--
Simon
_______________________________________________
Insight-developers mailing list
Insight-developers at itk.org
http://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list