Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Memory Problem!!!!!!!!!

Status
Not open for further replies.

rajanikant

Programmer
May 27, 2001
2
US
Here gOES....

I have a ** pointer "cohesion_table". I have allocated memory and written data into it. Now I want to copy it into a new **pointer array called "tree_table".

The code below is simple 2 loop structure to copy one table into another. NOW THE STRANGE THING HAPPENS.

It works fine until i=12 and j=236. Here after
tree_table[12][236]=cohesion[12][236]
the pointer for cohesion[12] becomes 0x0.....????
It has a valid address until then.

Any Idea Why???

**************************************

The 2 loop structure if U need them

****************************************

for(i=0;i<assigned_port_ct;i++)
{
tree_table=( int *)
my_malloc(assigned_port_ct*sizeof(int));

for(j=0;j<assigned_port_ct;j++)
{
tree_table[j]=cohesion_table[j];

}
}




 
Have you allocate tree_table itself (and how)?
And what is the value of assigned_port_ct?
 
Pls mail the full code u know memory problem lies where it is least expected.
Regards,
SwapSawe.
 
As mentioned above, your code sample is incomplete. But your problem probably stems from the fact that you're overwriting past your array bounds. i should not get as high as 12 and j should not get as high as 236 given the definition of tree_table.

Since array indices begin at 0, the highest subscripts for tree_table are 11 and 235.

Russ
bobbitts@hotmail.com
 
Thanks for all the help.

I screwed Up by writing into a pointer after freeing it.
That casused the problem here.

Rajani
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top