• Advertisement

Archived

This topic is now archived and is closed to further replies.

zeromemory

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a problem understanding this portion of the code:
  
PlayArea* playarea[10][20];

CrystalApp::CrystalApp()
	   : ...		
{
	ZeroMemory(object, sizeof(object) );
        ZeroMemory(object1, sizeof(object1) );
	ZeroMemory(crystal_a, sizeof(crystal_a) );
	ZeroMemory(crystal_b, sizeof(crystal_b) );
    
	for( int j=0; j<10; j++)
	{
	        ZeroMemory(playarea[j], sizeof(playarea[j]) );
	}
}
  
this constructor is trying to initialize the array of pointers. the 1st 4 zeromemory codes are for 1D array of pointers. what i dun understand is the playarea portion which is 2D. Am i initializing it correctly? anyone who can clarify my doubts will be most appreciated.

Share this post


Link to post
Share on other sites
Advertisement
No like this:

ZeroMemory(playarea, sizeof(playarea[0])*10);

But the code you wrote in your original post should also be fine. What is it you don''t understand about it?

Share this post


Link to post
Share on other sites
Edwinnie and felonius, you both posted the same thing . Yes, Edwinnie, that''s what I meant. If you''re being confused by the pointer part of that 2D array, remember that''s the ''last'' part ''interpreted''. I.E. it''s an 10 by 20 array of pointers to PlayAreas. So, on 32bit platforms, sizeof(playarea) is 800; and sizeof(playarea[0]) is 80, which we multiply by 10 to get 800.

Share this post


Link to post
Share on other sites
Ark, I think my brain is damaged today.

I almost always use pointers to a block of allocated data - not arrays with a given size and in that case the two notation forms are *not* the same.

Share this post


Link to post
Share on other sites

  • Advertisement