Horde3D

Next-Generation Graphics Engine
It is currently 27.04.2024, 09:54

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: C++ Boost libraries ?
PostPosted: 04.09.2008, 15:11 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
C++ Boost libraries are too popular these days.
They offer comfortable libraries for C++ programmers [depending on google and wikipedia]

I've seen some examples about multithreading with them; Multithreading with C++ Boost is too similar with high level languages such as C# .net

Is there anybody that have some experience with them ? Please write your experiences and it's benefits :!:


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2008, 16:25 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
You would probably be better off posting this type of question on a more general forum - GameDev.net is one of the best and largest, and quite a few of us from these forums also hang out there.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2008, 18:29 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
I'd say they are bloated :)

Never used them though.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2008, 20:15 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
I use certain aspects of Boost pretty extensively. The threading library is excellent, the smart pointer and container libraries are already in the C++ TR1 and TR2 specs and are essential to writing robust, maintainable C++ code. Spirit is a very useful parser framework, Phoenix and MPL are excellent for meta-programming both at the template and macro level.

All in all, Boost brings C++ somewhere close to the ease of use of a more modern language such as C# or Objective-C, but even so, C++ doesn't (and really can't) ever attain that.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 05.09.2008, 08:56 
Offline

Joined: 23.04.2008, 14:42
Posts: 6
Well, for starters, I find boost::python excellent. It may be that I'm doing something conceptually very wrong, but I find the python<->C++ interaction very easy to work with when using boost::python. It took me something like 50 lines of code to connect my C++ renderer, and PyCairo to create 2D vector graphics textures in python.

I have also worked with the boost thread libraries, and it took me practically no code to create a base class that allowes me to use threads Java style.

Example base class:

Code:
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/progress.hpp>
#include <boost/bind.hpp>
#include <boost/thread/condition.hpp>
#include <boost/utility.hpp>

#include <iostream>

/** */
class Thread : private boost::noncopyable {
  private:
    boost::condition thread_condition;
    boost::mutex monitor;

    /** */
    virtual void __run() {
      std::cout << "before run()" << std::endl;
      run();
      std::cout << "after run()" << std::endl;
      delete this;
    }

  public:

    /** */
    virtual void run() = 0;

    /** */
    virtual void sleep(const int nseconds) {
      boost::xtime t;
      boost::xtime_get(&t, boost::TIME_UTC);
      t.nsec += nseconds;
      boost::thread::sleep(t);
    }

    /** */
    virtual void start() {
      boost::thread th(boost::bind(&Thread::__run, this));
    }

  protected:
    /** */
    virtual void wait() {
      boost::mutex::scoped_lock thread_lock(monitor);
      thread_condition.wait(thread_lock);
    }

    /** */
    virtual void notify() {
      thread_condition.notify_one();
    }

    Thread() {
      std::cout << "Thread created." << std::endl;
    }

    virtual ~Thread() {
      std::cout << "Thread destroyed." << std::endl;
    }
};


And example of derived class:
Code:
/** */
class MyThread : public Thread {
  private:
    int id;
  public:
    MyThread(int _id) : id(_id) {}

    /** */
    void run() {

        std::cout << "Thread[" << id << "] starting.." << std::endl;
        sleep(2);
        std::cout << "Thread[" << id << "] waiting.." << std::endl;
        wait();
        std::cout << "Thread[" << id << "] notified. done." << std::endl;
    }

    /** */
    void doStuff() {
      notify();
    }

  private:
    ~MyThread() {
      std::cout << "Thread[" << id << "] destroyed." << std::endl;
    }
};


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group