Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: Beginner
Oct 29, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Static initialization and free store

Is it valid to attempt to allocate (via 'new()') dynamic memory prior to 'main()'? I am working on software that has static *'s to class objects, and through some rather nasty macro expansion, these object ptrs attempt to instantiate themselves via the 'new()' operator. I am working on Irix 6.2 and the software used to work fine under the Irix O32 ABI. When we ported to the N32 ABI, it started seg faulting and Purify reports IPR/IPW fatal errors throughout these static initializers.

If I understand, you are declaring data outside of any functions something like this:

CData* pData = new CData[100];
In my experience (mostly in Visual C++ for Intel), this works fine. The data is, in fact, allocated, and this line executes before the call to main. I have never run across problems with this. If you are having trouble, it may be specific to the platform you're porting to.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date