Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sharing data for several DLLs

Posted on 2002-06-19
5
Medium Priority
?
379 Views
Last Modified: 2012-08-13
Hello!
I have several DLLs and I want them to use the same data. I've created a SingleTon class in which I hold the common data (which are static pointers!). all my DLLs are accessing that SingleTon using some interface methods, that handle all the treatment in the common data pointers. when the DLLs are being loaded, the common data pointers in the SingleTon are being initialized. the problem is: I want the common data pointers to be init only ONCE, no matter how manny DLLs there are, but the current situation is that the common data pointers are being init for each DLL individually. How can I share the same data exactly for all the DLLs?
0
Comment
Question by:osnat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7092311
Try these links

http://codeproject.com/threads/sharedmemipc.asp
http://codeproject.com/threads/sm.asp

This will give the idea of shared memory.

GOOD LUCK
0
 
LVL 86

Accepted Solution

by:
jkr earned 600 total points
ID: 7092496
>>How can I share the same data exactly for all the DLLs?

As you aren't sharing the singleton over process boundaries, I'd go about it like this:

(sample for a stringstrem singleton that serves as a global logging buffer):

// a singleton...
template<class _T> class __singleton {

private:

    class __instance_ptr {

    public:

        __instance_ptr () : m_ptr ( NULL) {}

        ~__instance_ptr () { delete m_ptr; }

        _T* get () {

             return m_ptr;
           }

        void set ( _T* __p) {

            if ( __p) {

                delete m_ptr;

                m_ptr = __p;
            }
        }

    private:

        _T* m_ptr;
    };

    static __instance_ptr sm_ptr;

    __singleton ();
    __singleton ( const __singleton&);
    __singleton& operator= ( const __singleton&);

public:

    static _T* instance() {

        if ( !sm_ptr.get()) {

            sm_ptr.set ( new _T ());
        }

        return sm_ptr.get();
    }
};

typedef __singleton<stringstream> LogBuf;
// ensures that it is only initialized ONCE
#ifdef __THE_DLL_THAT_HOLDS_THE_SINGLETON LogBuf::__instance_ptr LogBuf::sm_ptr;
extern stringstream* g_pssLogBuf = LogBuf::instance ();
#else
extern stringstream* g_pssLogBuf;
#endif


stringstream*
declspec ( dllexport)
GetSingletonStringstream  () { return g_pssLogBuf;};



0
 
LVL 1

Expert Comment

by:senohp
ID: 7094992
Dear osnat,

You can share your DLL's variables using  memory map file or #pragma  data_seg(".myseg")

Here is some examples

#pragma data_seg (".myseg")
   int i = 0;
   char a[32]n = "hello world";
#pragma data_seg()

For more detail, please refer to :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_How_do_I_share_data_in_my_DLL_with_an_application_or_with_other_DLLs.3f.asp
0
 
LVL 11

Expert Comment

by:griessh
ID: 7262409
Dear osnat

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7332963
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question