[Insight-users] A memory issue

Ali Mouizina ali.mouizina at gmail.com
Sun Jan 22 17:35:50 EST 2012


I rebuilt everything as you suggested. Now, I can allocate my 4D vector but
I'm currently having another problem. When I try to set new values in my
vector it crashes after a few iterations. 

Here's the code : 


	typedef unsigned char PixelType_weight;
	const unsigned int Dimension4=4;
	typedef itk::Image<PixelType_weight, Dimension4> Weightimage;


	Weightimage::Pointer weight = Weightimage::New();

	
	Weightimage::IndexType start,pixelIndex_weight;
	start[0]=0;
	start[1]=0;
	start[2]=0;
	start[3]=0;

	Weightimage::SizeType size;
	size[0]=nb_col; //-> nb_col is set in the constructor
	size[1]=nb_ln;
	size[2]=nb_slice;
	size[3]=124; 

	
	Weightimage::RegionType region;
	region.SetSize(size);
	region.SetIndex(start);
	
	weight->SetRegions(region);
	weight->Allocate(); // -> It no longer crashes here
	weight->FillBuffer(0);

	for (int l=0;l<124;l++){ // --> After a few iterations it crashes
		for (int i=0;i<nb_ln;i++)
			for (int j=0;j<nb_col;j++)
				for (int k=0;k<nb_slice;k++){
					pixelIndex_weight[0]=j;
					pixelIndex_weight[1]=i;
					pixelIndex_weight[2]=k;
					pixelIndex_weight[3]=l;
	
weight->SetPixel(pixelIndex_weight,'ÿ'); 
				}
	}

Any idea why does it crash ? Maybe I'm doing a buffer overflow ? ...

Regards,

Ali

-----Message d'origine-----
De : John Drescher [mailto:drescherjm at gmail.com] 
Envoyé : vendredi 20 janvier 2012 17:19
À : Ali Mouizina; Insight Users
Objet : Re: [Insight-users] A memory issue

On Fri, Jan 20, 2012 at 10:07 AM, Ali Mouizina <ali.mouizina at gmail.com>
wrote:
> I'm currently working on a 32 bits program. Do you think that I should 
> set my project's settings to work with 64 bits to avoid this memory issue
?
>

Yes. Remember that you will have to rebuild itk and all other libraries
included in your project.

John



More information about the Insight-users mailing list