We help IT Professionals succeed at work.

init shared memory + strange compilation error

allallall asked
Last Modified: 2013-11-20
I use shared memory inside my dll.
(#pragma data_seg )

I must initialize all verbs i put in that segment (if not ever process that loads the dll will get its own copy of the shared verbs).
It is easy to init primitive, but can i put object there?
How can i init it?
#pragma data_seg
Myobj o=???;
#pragma data_seg()

I read somewhere that if i init a class member inside the constructor then that will be ok but it did not work.
#pragma data_seg
Myobj o(5);
#pragma data_seg()
(the object was not shared and each process that loaded the dll got its on copy).

What can i do?

2)I have this code:
class AAA : CDialog

void main()
AAA *o = new AAA();
If i run it i get:
error C2247: 'new' not accessible because 'CDialog' uses 'public' to inherit from 'CWnd'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : see declaration of 'new'
error C2247: 'delete' not accessible because 'CDialog' uses 'public' to inherit from 'CWnd'
c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(676) : see declaration of 'delete'

So i tried to use malloc and it worked, it did not gave that error.
The problem with malloc is that it does not call the constructor and i need that constructor to be called since i do things in the constructor that must be done only there.

Any workaround here?

Watch Question

Top Expert 2012
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks Jkr.

Are you absolutely sure that you can not put object (not pointer) in the shared segment?
Top Expert 2012

There are (dirty) tricks to do so, but in general, I would advise against doing so. One option would be to use a shared memory area with 'placement new' to construct an object there, but if that thing has more complec data types, you will run in trouble sooner or later.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.