placement new with Sun CC 6
I'm trying to create the shared hash_map in shared memory for the two different processes to access it.
I've implemented the "Shared memory allocator" for the hash_map to place the data dynamically in shared memory.
But, now I am facing the problem that, when the server process instantiates this hash_map and populates the data in it, the client process is not able to access this hash_map.
As a work around, I created a pointer to this map in a shared memory and made this as a "static pointer" in a shared library statically linked to server & client processes.
Then I used placement new to set the pointer returned by "shmat" to set the hash_map pointer.
But still the client process is not getting that hash_map pointer.
Is placement new supported by Solaris 8 (CC: Sun WorkShop 6 update 2 C++ 5.3 Patch 111685-24 2006/11/03).
Please help, guide. Many thanks for your time & help.
# 1
Although your compiler is End of LIfe and essentially unsupported, it does support placement new.
The hash_map class is not part of the C++ libraries supported by Sun C++. Perhaps the design of the class does not support use of shared memory. That is, it probably does internal allocations that ignore your placement new. Assuming the has_map allows you to provide an allocator class as a template parameter, you might need to provide your own allocator.
Unless there is a particular reason why you need ot use WS6u2, I strongly recommend upgrading to the current release, Sun Studio 11, which is free. You can get it here:
http://developers.sun.com/sunstudio/
# 2
My code was working for "placement new", but the problem was that when the client instantiated the map pointer in shared memory using "placement new", it wiped out all the data which was populated by server.
This the normal behavior of new, it by default clears the memory which is allocates.
But this is problem in my case. Now, I've to see how can I avoid this clearing of memory.