|
From: Raghunath Marella.S <ms...@ya...> - 2002-06-10 11:24:02
|
Hi,
Please find my reply embedded...
--- Ioannis Vranos <no...@ho...> wrote:
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...]
> On Behalf
> > Of Raghunath Marella.S
> > Sent: Monday, June 10, 2002 10:25 AM
> > To: Dev-C++ Mailing List
> > Subject: RE: [Dev-C++] memory violation....
> >
> >
> > Hi Ioannis/Jason/Others,
> >
> > Please find the piece of code where the memory
> > violation is seen. I have not deleted the pointer
> and
> > accessed after that. No error has been done from
> my
> > side.
>
>
> It is 100% some logical error (bug). To avoid
> situations like this and
> have bullet proof code use the standard library
> containers instead of
> explicit memory allocation and deallocation.
> Examples can be seen below.
Logical error in my code or VC++ COmpiler??
>
> #include <vector>
>
> using namespace std;
>
>
> > int *EleTopo=new int[seneles*sennds];
>
> vector<int>EleTopo(seneles*sennds);
>
>
> > char *NodeSign=new char[this->NNodes+1];
>
> list, or vector, or string, or something...
>
>
>
> > Similarly few other variables have been
> dynamically
> > allocated....
> >
> > for(int i=0;i<seneles;i++)
> > for(int j=0;j<ncn;j++)
> > {
> > int cuEl = (theSubEle+ise)->SEtopo[i];
> >
> >
> *(EleTopo+i*ncn+j)=(theElement+cuEl-1)->topo[j];
> > NodeSign[(theElement+cuEl-1)->topo[j]] =
> > 'P';//All nodes are marked as positive initially.
> > }
> > After this piece of code, 'EleTopo' values are
> > printed and they confirmed to be correct.
>
>
> It is too messy! *(EleTopo+i*ncn+j)? What about the
> equivallent
> EleTopo[i*ncn+j] (which is somewhat messy too).
> Obviously you come from
> a hardcore C background and carry all that low stuff
> bagage. :)
Yes, it is equivalent to EleTopo[i][j] where are 'j'
ranges between 0 to ncn.
>
>
>
> >
> > After few lines of other code.....
> >
> > for(int iel=seneles-1;iel>=0 ; iel--)
> > {
> > int iLocalForEle=0;
> > int curElement = (theSubEle+ise)->SEtopo[iel];
> > if(iel==seneles-1)
> > coutf << "\n Final element in the SE
> is...:"<<iel;
> > //newAdd
> > int AnyNode;
> >
> >
> > int noOfDf = 0;
> > NoOfNegNodes =0;
> > for(int j=0;j<ncn;j++)
> > {
> > AnyNode = *(EleTopo+iel*ncn+j);
> > int isThisNodeABN = 0;// is this a boundary
> node
> > of SE.
> > for(int it=0;it<SeBNodes;it++)
> > {
> > if(AnyNode ==
> > ((theSubEle+ise)->SEBounNodes[it]))
> > {
> > isThisNodeABN = 1;
> > break;
> > }
> > else
> > isThisNodeABN = 0;
> > }
> >
> > if(isThisNodeABN==0)
> > {
> >
> > ****** if(NodeSign[*(EleTopo+iel*ncn+j)]=='N')
> > {
> > //Do nothing...
> > }
> > else
> > {
> > NodeSign[*(EleTopo+iel*ncn+j)]='N';
> > int nde = *(EleTopo+iel*ncn+j);
> > ****** *(EleTopo+iel*ncn+j) =
> > -*(EleTopo+iel*ncn+j);
> > NoOfNegNodes++;
> >
> > //saving the the dfs that are going to
> > be removed
> > after this element being assembled.
> > for(int ir=0;ir<NDF;ir++)
> > {
> > *(DfToRemove+iel*(ncn*NDF)+iLocalForEle)=
> > (nde-1)*NDF+ir;
> > iLocalForEle++;
> > }
> > noOfDf+=NDF;
> > }
> > }
> > else
> > cout <<"\n this Node is a BoundaryNode of
> > SE...:"<<AnyNode<<".."<<ise;
> > }
> > noOfDf = iLocalForEle;
> > NoNegDf[iel]=NDF*NoOfNegNodes;
> > }//sign check ends here.....
>
>
>
> If any exception is thrown from somewhere there,
> much of all those
> allocated resources remain allocated.
>
>
>
> >
> >
> > The problem appears in the line marked with
> ******.
> > Actually this problem is seen only in some of the
> > problems. To give you more idea, I have tested
> this
> > code as standalone, it worked fine for 'EleTopo'
> > sized upto 3200*6, then it worked properly and no
> > memory violation was observed.
> >
> > But, when the code used as a server
> implementation in
> > CORBA environment, the so called memory violation
> > took place when 'EleTopo' was sized to 800*6.
> Briefly,
> >
> > 'EleTopo' is like an two dimentional array of
> size
> > [800][6]. I have to access data in 'EleTopo' from
> the
> > end, ie., from [800][].
>
> [799][].
yes, it is [799][]
>
>
>
> The values are correct till
> > [48][6] and started giving junk values for some of
> the
> > indexes between [47][] to [0][].
> >
> > I have shown in array form just for illustration
> > purpose.
> >
> > I am clueless how this memory violation is taking
> > place in some cases only.
> >
> > Will you pls suggest me what is going wrong in
> this.
>
>
> What is going wrong basically here is that you use
> C++ in the place of
> assembly programming. Deal C++ as a high level
> programming language and
> you can even gain some time/space! I suggest you
> read "The C++
> Programming Language" 3rd Edition or Special
> Edition. And be prepared
> for a life change. :)
Thank you.
>
>
> Ioannis
>
regards,
Raghunath
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
|