[Insight-users] Image offset is giving bad pointer for large datasets (7Gb)
Mike Jackson
mike.jackson at bluequartz.net
Sat Jul 11 13:23:21 EDT 2009
Luis,
you make a good argument through a nice concise explanation. Got my vote.
Mike
On Sat, Jul 11, 2009 at 11:34 AM, Luis Ibanez<luis.ibanez at kitware.com> wrote:
>
> Hi Mike,
>
> OffsetValueType is certainly not intended to be a Pointer,
> but indeed to be the difference between two pointers.
>
> The typical use of OffsetValueType is to locate a pixel
> in the block of memory of an image:
>
> OffsetValueType offset = 555;
> image->GetBuffer() + offset;
>
> The other use of OffsetValueType is to be the components
> of the differences between two indices, which by extension
> should make us consider using ptrdiff_t also as the component
> type of the itk::Index and the itk::Size, since it is a valid use
> to allocate a 1D image of 10Gb.
>
> I'm not sure that the argument of whether some programmer
> may get confused, should take precedence over the argument
> of what is the correct type to use.
>
> The first problem gets solved with three lines of comments
> in the declaration of
>
> /** Here we explain why... */
> typedef ptrdiff_t OffsetValueType
>
> Following basic practices of Generic Programming, in all
> subsequent ITK code, we should use the type "OffsetValueType"
> and there is no need to expose what OffsetValueType actually is.
>
>
> Users that digg deep into the code will be already confused
> by the fact that different platforms define "int" and "long" in
> different ways. What is interesting about ptrdiff_t is that is
> clearly defined in a platform-independent way.
>
>
> The best way to protect people from ignorance,
> is to actually educate them. :-)
>
>
> Luis
>
>
> --------------------------------------------------------------------------------------
> On Sat, Jul 11, 2009 at 8:50 AM, Mike Jackson <mike.jackson at bluequartz.net>
> wrote:
>>
>> I think the only thing I have against using ptrdiff_t is that it
>> doesn't describe exactly what you are wanting in a type. ptrdiff_t is
>> the result of subtraction between two _pointers_. Is OffsetValueType
>> really a Pointer or an index into an array? I think if programmers
>> started digging when debugging and saw ptrdiff_t then that might be
>> confusing to them as they might start thinking that they can cast an
>> OffsetValueType to a pointer and start doing pointer manipulations on
>> it.
>> It seems to me that OffsetValueType is just that, a _value_, and
>> not a pointer. Also, do we fully understand how ptrdiff_t is defined
>> on all the platforms that ITK runs on? Can we be sure we take that
>> into account properly? In comparison we know _exactly_ how it behaves
>> because we would be using either "int" or "long long int" which also
>> has the advantage of describing exactly what we need, a plain old
>> signed integer. Again, when new ITK programmers start digging to find
>> out what OffsetValueType and come up with a plain old integer there
>> most likely will not be any misunderstanding about the type.
>>
>> Mike Jackson
>>
>> On Sat, Jul 11, 2009 at 7:02 AM, Luis Ibanez<luis.ibanez at kitware.com>
>> wrote:
>> >
>> > What's wrong with using : ptrdiff_t ?
>> >
>> >
>> > Luis
>> >
>> >
>> > -----------------------------------------------------------
>> > On Fri, Jul 10, 2009 at 8:34 PM, Mike Jackson
>> > <mike.jackson at bluequartz.net>
>> > wrote:
>> >>
>> >> Probably should have googled that first. Seems to be a POSIX extension
>> >> so probably isn't that portable.
>> >>
>> >> From an earlier email:
>> >> ------
>> >> On recent realization:
>> >>
>> >> "size_t" is unsigned :-/
>> >>
>> >> and we need the OffsetValueType to be signed,
>> >> since we use it to compute differences...
>> >> ------
>> >> so why doesn't ITK just define it to int or long long int depending on
>> >> the size of size_t? That test could be run during CMake time like all
>> >> the others?
>> >>
>> >> #if size_of_size_t == 4
>> >> typedef signed int OffsetValueType;
>> >> #elif size_of_size_t == 8
>> >> typedef signed long long int OffsetValueType;
>> >> #endif
>> >>
>> >> Of course we would probably want to use the predefined 64 bit type
>> >> that the ITK/CMake tests come up with: __int64, _int64_t, int64_t or
>> >> whatever they are..
>> >>
>> >> Just my thoughts?
>> >> Mike
>> >>
>> >> On Fri, Jul 10, 2009 at 8:23 PM, Mike
>> >> Jackson<mike.jackson at bluequartz.net> wrote:
>> >> > Is there a "ssize_t" type? Or is that some contrived type on some of
>> >> > the projects that I work on?
>> >> >
>> >> > Mike
>> >> >
>> >> > On Fri, Jul 10, 2009 at 6:29 PM, Luis Ibanez<luis.ibanez at kitware.com>
>> >> > wrote:
>> >> >>
>> >> >> On recent realization:
>> >> >>
>> >> >> "size_t" is unsigned :-/
>> >> >>
>> >> >> and we need the OffsetValueType to be signed,
>> >> >> since we use it to compute differences...
>> >> >>
>> >> >> It seems that what we need is the type
>> >> >>
>> >> >> "ptrdiff_t"
>> >> >>
>> >> >> which is supposed to represent the differences
>> >> >> between two pointers, and therefore should be
>> >> >> capable of measuring distances between any
>> >> >> two locations in memory.
>> >> >>
>> >> >> I'm now rerunning the Experimental with
>> >> >> "ptrdiff_t" instead of "size_t".
>> >> >>
>> >> >>
>> >> > Luis
>> >> >
More information about the Insight-users
mailing list