Advertisement

zeromemory

Started by May 31, 2002 11:52 PM
4 comments, last by edwinnie 22 years, 6 months ago
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.
Just do another sizeof based ZeroMemory. It''s a contiguous array, so it''s safe.

Advertisement
huh?
hmm...u mean this?

ZeroMemory(playarea, sizeof(playarea) );

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?
Jacob Marner, M.Sc.Console Programmer, Deadline Games
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.

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.
Jacob Marner, M.Sc.Console Programmer, Deadline Games

This topic is closed to new replies.

Advertisement