Discussion:
[ITK-users] Variable Matrix Access Violiotation
Fabian Torres
2017-08-30 16:24:27 UTC
Permalink
Hi evryone.

IÂŽm using itk VariableMatrix to do some image processing. But I have some
problems initializing my matrices.
When I use small sizes like this I do not have any problem

//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);

But when I use bigger sizes like:

regionSize[0] = 100;
regionSze[1] = 100;

I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.

I'm using Visualstudio 2008 and ITK 4.4

Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?

Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
E-mail ***@gmail.com, ***@gmail.com
Francois Budin
2017-09-11 17:37:47 UTC
Permalink
Hello Fabian,

You are most likely allocating more memory than what your computer can
allocates. If you compute the memory required for your matrix, it will be
at least:
8 (long doubles on Visual Studio C++ are the same size as doubles) *
2*100*100*2*100*100 = 3 200 000 000 Bytes

This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will
run into errors.

Hope this helps,
Francois
Post by Fabian Torres
Hi evryone.
IÂŽm using itk VariableMatrix to do some image processing. But I have some
problems initializing my matrices.
When I use small sizes like this I do not have any problem
//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);
regionSize[0] = 100;
regionSze[1] = 100;
I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.
I'm using Visualstudio 2008 and ITK 4.4
Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?
Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Lowekamp, Bradley (NIH/NLM/LHC) [C]
2017-09-11 17:47:53 UTC
Permalink
Oh! I think you are experiencing integer overflow with that size of a matrix. The value Francois (correctly) computed 3,200,000,000 is ~3GB which is greater than numeric_traits<int>::max(), which for 32-bit singed integers is 2,147,483,647. The internal implementation of this class is vnl_matrix, so the integer limitation lies within that library. So you matrix is too big for this library.

When I looked at this e-mail earlier I miss computed the size, so I didn’t realized this problem.

HTH,
Brad


From: Francois Budin <***@kitware.com>
Date: Monday, September 11, 2017 at 1:38 PM
To: Fabian Torres <***@gmail.com>
Cc: "insight-***@itk.org" <insight-***@itk.org>
Subject: Re: [ITK-users] Variable Matrix Access Violiotation

Hello Fabian,
You are most likely allocating more memory than what your computer can allocates. If you compute the memory required for your matrix, it will be at least:
8 (long doubles on Visual Studio C++ are the same size as doubles) * 2*100*100*2*100*100 = 3 200 000 000 Bytes
This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will run into errors.
Hope this helps,
Francois


On Wed, Aug 30, 2017 at 12:24 PM, Fabian Torres <***@gmail.com<mailto:***@gmail.com>> wrote:
Hi evryone.

IÂŽm using itk VariableMatrix to do some image processing. But I have some problems initializing my matrices.
When I use small sizes like this I do not have any problem

//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);

But when I use bigger sizes like:

regionSize[0] = 100;
regionSze[1] = 100;

I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.

I'm using Visualstudio 2008 and ITK 4.4

Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?

Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
E-mail ***@gmail.com<mailto:***@gmail.com>, ***@gmail.com<mailto:***@gmail.com>

_____________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

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://public.kitware.com/mailman/listinfo/insight-users
Francois Budin
2017-09-11 17:56:28 UTC
Permalink
@Brad: I looked in the source code and the types of the column and row size
variables are "unsigned int" which should allow up to 2^32-1 so 4GB, isn't
that correct?

On Mon, Sep 11, 2017 at 1:47 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Oh! I think you are experiencing integer overflow with that size of a
matrix. The value Francois (correctly) computed 3,200,000,000 is ~3GB which
is greater than numeric_traits<int>::max(), which for 32-bit singed
integers is 2,147,483,647. The internal implementation of this class is
vnl_matrix, so the integer limitation lies within that library. So you
matrix is too big for this library.
When I looked at this e-mail earlier I miss computed the size, so I didn’t
realized this problem.
HTH,
Brad
*Date: *Monday, September 11, 2017 at 1:38 PM
*Subject: *Re: [ITK-users] Variable Matrix Access Violiotation
Hello Fabian,
You are most likely allocating more memory than what your computer can
allocates. If you compute the memory required for your matrix, it will be
8 (long doubles on Visual Studio C++ are the same size as doubles) *
2*100*100*2*100*100 = 3 200 000 000 Bytes
This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will run into errors.
Hope this helps,
Francois
Hi evryone.
IÂŽm using itk VariableMatrix to do some image processing. But I have some
problems initializing my matrices.
When I use small sizes like this I do not have any problem
//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);
regionSize[0] = 100;
regionSze[1] = 100;
I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.
I'm using Visualstudio 2008 and ITK 4.4
Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?
Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Lowekamp, Bradley (NIH/NLM/LHC) [C]
2017-09-11 18:08:11 UTC
Permalink
Yes, unsigned int’s max is ~4GB, so it “could” work. But working with unsigned integers in the 2GB-3GB range is problematic and trick when subtraction and offsets need to be computed. It is a big red flag to me.

Another possibility, is that the program was just compiled in 32-bit mode. I don’t think a win32 application can allocate that much memory.

Brad



From: Francois Budin <***@kitware.com>
Date: Monday, September 11, 2017 at 1:57 PM
To: "Lowekamp, Bradley (NIH/NLM/LHC) [C]" <***@mail.nih.gov>
Cc: Fabian Torres <***@gmail.com>, "insight-***@itk.org" <insight-***@itk.org>
Subject: Re: [ITK-users] Variable Matrix Access Violiotation

@Brad: I looked in the source code and the types of the column and row size variables are "unsigned int" which should allow up to 2^32-1 so 4GB, isn't that correct?

On Mon, Sep 11, 2017 at 1:47 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <***@mail.nih.gov<mailto:***@mail.nih.gov>> wrote:
Oh! I think you are experiencing integer overflow with that size of a matrix. The value Francois (correctly) computed 3,200,000,000 is ~3GB which is greater than numeric_traits<int>::max(), which for 32-bit singed integers is 2,147,483,647. The internal implementation of this class is vnl_matrix, so the integer limitation lies within that library. So you matrix is too big for this library.

When I looked at this e-mail earlier I miss computed the size, so I didn’t realized this problem.

HTH,
Brad


From: Francois Budin <***@kitware.com<mailto:***@kitware.com>>
Date: Monday, September 11, 2017 at 1:38 PM
To: Fabian Torres <***@gmail.com<mailto:***@gmail.com>>
Cc: "insight-***@itk.org<mailto:insight-***@itk.org>" <insight-***@itk.org<mailto:insight-***@itk.org>>
Subject: Re: [ITK-users] Variable Matrix Access Violiotation

Hello Fabian,
You are most likely allocating more memory than what your computer can allocates. If you compute the memory required for your matrix, it will be at least:
8 (long doubles on Visual Studio C++ are the same size as doubles) * 2*100*100*2*100*100 = 3 200 000 000 Bytes
This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will run into errors.
Hope this helps,
Francois


On Wed, Aug 30, 2017 at 12:24 PM, Fabian Torres <***@gmail.com<mailto:***@gmail.com>> wrote:
Hi evryone.

IÂŽm using itk VariableMatrix to do some image processing. But I have some problems initializing my matrices.
When I use small sizes like this I do not have any problem

//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);

But when I use bigger sizes like:

regionSize[0] = 100;
regionSze[1] = 100;

I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.

I'm using Visualstudio 2008 and ITK 4.4

Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?

Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
E-mail ***@gmail.com<mailto:***@gmail.com>, ***@gmail.com<mailto:***@gmail.com>

_____________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

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://public.kitware.com/mailman/listinfo/insight-users
Fabian Torres
2017-09-11 21:30:16 UTC
Permalink
Hi.



Thanks for your responses; all of them gave me some perspective on the
problem.

Indeed the size of my matrix is around 3GB and I do have enough memory
space to allocate it.



So I think the problem lies in the integer overflow and that my program is
compiled in 32-bit mode, so my win32 cannot allocate that size of matrix.



So what do you recommend? use another kind of structure that it is not an
itk matrix and compiling this project in 64bits?



Thank you very much. I do appreciate the time you took for this subject.

On Mon, Sep 11, 2017 at 1:08 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Yes, unsigned int’s max is ~4GB, so it “could” work. But working with
unsigned integers in the 2GB-3GB range is problematic and trick when
subtraction and offsets need to be computed. It is a big red flag to me.
Another possibility, is that the program was just compiled in 32-bit mode.
I don’t think a win32 application can allocate that much memory.
Brad
*Date: *Monday, September 11, 2017 at 1:57 PM
*Subject: *Re: [ITK-users] Variable Matrix Access Violiotation
@Brad: I looked in the source code and the types of the column and row
size variables are "unsigned int" which should allow up to 2^32-1 so 4GB,
isn't that correct?
On Mon, Sep 11, 2017 at 1:47 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <
Oh! I think you are experiencing integer overflow with that size of a
matrix. The value Francois (correctly) computed 3,200,000,000 is ~3GB which
is greater than numeric_traits<int>::max(), which for 32-bit singed
integers is 2,147,483,647. The internal implementation of this class is
vnl_matrix, so the integer limitation lies within that library. So you
matrix is too big for this library.
When I looked at this e-mail earlier I miss computed the size, so I didn’t
realized this problem.
HTH,
Brad
*Date: *Monday, September 11, 2017 at 1:38 PM
*Subject: *Re: [ITK-users] Variable Matrix Access Violiotation
Hello Fabian,
You are most likely allocating more memory than what your computer can
allocates. If you compute the memory required for your matrix, it will be
8 (long doubles on Visual Studio C++ are the same size as doubles) *
2*100*100*2*100*100 = 3 200 000 000 Bytes
This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will run into errors.
Hope this helps,
Francois
Hi evryone.
IÂŽm using itk VariableMatrix to do some image processing. But I have some
problems initializing my matrices.
When I use small sizes like this I do not have any problem
//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*regionSize[1]);
matA.Fill(0.0);
regionSize[0] = 100;
regionSze[1] = 100;
I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.
I'm using Visualstudio 2008 and ITK 4.4
Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?
Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
E-mail ***@gmail.com, ***@gmail.com
Francois Budin
2017-09-12 12:42:27 UTC
Permalink
Hello Fabian,

In your case the limitation is really the fact that you compile your
project in 32bits. Using another kind of structure will lead to the same
issue as long as it is build in 32bits. So my advice is to compile your
project (and ITK) in 64 bits. It will work then (it works on my computer).

Hope this helps,
François
Post by Fabian Torres
Hi.
Thanks for your responses; all of them gave me some perspective on the
problem.
Indeed the size of my matrix is around 3GB and I do have enough memory
space to allocate it.
So I think the problem lies in the integer overflow and that my program is
compiled in 32-bit mode, so my win32 cannot allocate that size of matrix.
So what do you recommend? use another kind of structure that it is not an
itk matrix and compiling this project in 64bits?
Thank you very much. I do appreciate the time you took for this subject.
On Mon, Sep 11, 2017 at 1:08 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Yes, unsigned int’s max is ~4GB, so it “could” work. But working with
unsigned integers in the 2GB-3GB range is problematic and trick when
subtraction and offsets need to be computed. It is a big red flag to me.
Another possibility, is that the program was just compiled in 32-bit
mode. I don’t think a win32 application can allocate that much memory.
Brad
*Date: *Monday, September 11, 2017 at 1:57 PM
*Subject: *Re: [ITK-users] Variable Matrix Access Violiotation
@Brad: I looked in the source code and the types of the column and row
size variables are "unsigned int" which should allow up to 2^32-1 so 4GB,
isn't that correct?
On Mon, Sep 11, 2017 at 1:47 PM, Lowekamp, Bradley (NIH/NLM/LHC) [C] <
Oh! I think you are experiencing integer overflow with that size of a
matrix. The value Francois (correctly) computed 3,200,000,000 is ~3GB which
is greater than numeric_traits<int>::max(), which for 32-bit singed
integers is 2,147,483,647. The internal implementation of this class is
vnl_matrix, so the integer limitation lies within that library. So you
matrix is too big for this library.
When I looked at this e-mail earlier I miss computed the size, so I
didn’t realized this problem.
HTH,
Brad
*Date: *Monday, September 11, 2017 at 1:38 PM
*Subject: *Re: [ITK-users] Variable Matrix Access Violiotation
Hello Fabian,
You are most likely allocating more memory than what your computer can
allocates. If you compute the memory required for your matrix, it will be
8 (long doubles on Visual Studio C++ are the same size as doubles) *
2*100*100*2*100*100 = 3 200 000 000 Bytes
This means that you need to have at least that much memory available.
If your computer does not have this amount of memory available, you will run into errors.
Hope this helps,
Francois
Hi evryone.
IÂŽm using itk VariableMatrix to do some image processing. But I have some
problems initializing my matrices.
When I use small sizes like this I do not have any problem
//matrix A
regionSize[0] = 15;
regionSze[1] = 15;
VariableSizeMatrix<long double> matA;
matA.SetSize(2*regionSize[0]*regionSize[1],2*regionSize[0]*r
egionSize[1]);
matA.Fill(0.0);
regionSize[0] = 100;
regionSze[1] = 100;
I get an Acces Violation exception
Access violation reading location 0xcdcdcdc1.
I'm using Visualstudio 2008 and ITK 4.4
Does this has something to do with memory allocation?
Is there a way a could verify if I have enough memory to allocate my matrix?
Thanks.
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
--
Fabián Torres Robles
Maestría en Ciencias en Ingeniería Electrónica
Ingeniería en Sistemas Electrónicos
Tel. 58081280, 0445534661338
Loading...