Ajinkya Kale wrote:
> Just initialize the 2d array globally.....
> All global variables are intialized to 0.....
> 
> Chao,
> Ajinkya.

Global variables are a bad habit to get into.  In my case, I just fixed 
a number of initialization and shutdown _crash_ bugs due _specifically_ 
to using global variables.  Haven't had crash bugs in months.  The crash 
bugs were interdependency problems with global classes (one global class 
depended on another global class).  The compiler determines whatever 
order of initialization it feels like...but the class still sits there 
as if it existed.

At this point, you start getting into some pretty advanced C++ called 
'placement new' and 'placement delete'.  Dangerous stuff to use yourself 
if you don't know how it works, but the compiler allocates the memory 
for the object in advance (at compile time) and, at run-time, uses 
placement new to construct the object and placement delete to free the 
object at shutdown...and the compiler determines the order objects are 
constructed and deleted.  All of this is outside your control because it 
is done before and after main() is called.

Not saying globals are bad, just saying you have to be careful when 
using them.  I solved my problems by eliminating the interdependencies.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.4
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

http://www.CubicleSoft.com/VerifyMyPC/

Reply via email to