Storing IceStorm messages in the server side

josejose Member Jose ValletOrganization: Aalto UniversityProject: distributed data fusion in wireless networks
Hello.

I need to store sequences of incoming messages in the subscribers, and I am trying to figure out which is the correct and fastest way in terms of speed. My question is about memory allocation.

In order to handle messages in the subscriber side, the programmer has to implement a class of which a method will be called by IceStorm upon arrival of new messages. For clarity, in the clock example we can see (C++)

class ClockI : public Clock
{
public:

virtual void
tick(const string& time, const Ice::Current&)
{
cout << time << endl;
}
};

My question is: every time a new message arrives to the subscriber, does the subscriber a)allocate memory for each new message or b)write always in the same memory area?

Using the clock example as a reference, if a), then each reference to a string passed by argument to the tick method is a reference to a unique message, and I could simply store these references in a vector, for example.
If b) I will have to explicitly create a copy of each incoming message. In this case, I have not found any equal operator neither a clone method implemented. Is there an easy way to clone messages?

BR
Jose

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Jose,

    The Ice run-time allocates memory as needed for each new message. With the Clock demo, the Ice run-time allocates a new string and passes this string to the subscriber implementation (ClockI).

    Note that with Ice for C++, all types manage their memory: you never have to explicitly free or release a parameter that Ice gives to you.

    If you want to keep a copy of the const string& time parameter, you can't just store the reference as Ice will deallocate this object once the operation dispatch completes. You need to make a copy, for example into a vector<string> data member:
    class ClockI : ...
    {
    
    virtual void
    tick(const string& time, const Ice::Current&)
    {
         _timeVector.push_back(time);
    }
    
    private:
       vector<string> _timeVector;
    };
    
    

    I hope this is clearer now.

    Bernard
  • josejose Member Jose ValletOrganization: Aalto UniversityProject: distributed data fusion in wireless networks
    Thanks Bernard, this is clear now.

    I assume then that there are no clone method neither an "=" operator that ICE provides to replicate the messages, and that I have to manually create the copies, correct?

    BR
    Jose
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Jose,

    The parameters are regular C++ objects, like std::string. To copy a std::string, you would use its copy constructor, or copy it into another string through assignment.

    If you want to copy the whole message (as a sequence of bytes), for example to forward it as is to another application, have a look at Dynamic Invocation and Dispatch Overview - Ice 3.4 - ZeroC.

    Best regards,
    Bernard
Sign In or Register to comment.