Link to home
Create AccountLog in
Avatar of allallall
allallall

asked on

init shared memory + strange compilation error

1)
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.
I.E
#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
{
};

then:
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?

Thanks
 
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of allallall
allallall

ASKER

Thanks Jkr.

Are you absolutely sure that you can not put object (not pointer) in the shared segment?
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.