Hardware vs. software

This is my system:
Micro$oft Windows 98
DirectX 8.1
Asus P2B AGP 2x with the latest firmware
Pentium II 450 @112Mhz (overclocked, stable)
Matrox Mystique G200 with the latest firmware and drivers

if I use

screen = SDL_SetVideoMode(800, 600, 32 , SDL_HWSURFACE | SDL_FULLSCREEN);

blitting at 800x600x32 of a single, generic 32bpp SDL_Surface is MUCH slower than using

screen = SDL_SetVideoMode(800, 600, 32 , SDL_SWSURFACE | SDL_FULLSCREEN);

while if I remove SDL_FULLSCREEN, however, hardware and software become equivalent.

Why?

1)Anyone can explain me the syntax of the SDL_CreateThread call to pass it a generic fn(parameters)? I’m afraid I’m not very found on pointers to functions and the SDL
guide doesn’t help me…
2)Do you know any good concurrent programming tutorial?

	Thanks
  1. Take a look at
    http://www.inf.uni-konstanz.de/~kuehl/cpp/cppfaq.htm/pointers-to-members.html
    for information on function pointers…

Greeting
JakobOn Fri, Apr 12, 2002 at 09:45:06PM +0200, CRV?ADER/KY wrote:

1)Anyone can explain me the syntax of the SDL_CreateThread call to pass it a generic fn(parameters)? I’m afraid I’m not very found on pointers to functions and the SDL
guide doesn’t help me…
2)Do you know any good concurrent programming tutorial?

  Thanks

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I have been perusing the libsdl.org documentation regarding
SDL_CreateThread. The way I understand it, the only way to call a member
function of a class with SDL_CreateThread is to create a global wrapper
function. The posted example was the following:

class Sprite {
public:
int run();
};

int Sprite::run() {

}

int sprite_callback(void * obj) {
(Sprite*)sprite = obj;
return sprite->run();
}

SDL_CreateThread(sprite_callback,pThisSprite)

My particular problem is that I have 4 member functions within my client
class to be threaded and 4 member functions in my server class that I
want to run in threads.

This would require a bunch of global functions that I would rather not
pollute my code with. I am hoping someone here has a better idea as to
how to get around this problem. My apologies if this is more of a C/C++
programming question.

Also, another idea posted on sdldoc.csn.ul.ie was the following:

SDL_CreateThread(&MyClass::myFunction, (void*)this);

This, however, would seem to require the function to be declared static
which would introduce a whole new set of problems.

Thanks for any help.

Nicholas Groesz

nick at emilive.com wrote:

I have been perusing the libsdl.org documentation regarding
SDL_CreateThread. The way I understand it, the only way to call a
member function of a class with SDL_CreateThread is to create a
global wrapper function.

This would require a bunch of global functions that I would rather not
pollute my code with.

Well, they could be global, or they could be declared as static normal
functions (giving them just file scope rather than local scope), or you
could put them in an unnamed namespace (again, giving them file scope),
or you could make them into static member functions. I would choose one
of the last two. I am unsure why you think that making a function a
static member could be a problem - it is essentially the same as a
global function except it gains access to any typedefs or sub-classes
inside that class and you have more control over which other functions
can call it.–
Kylotan

My particular problem is that I have 4 member functions within my client
class to be threaded and 4 member functions in my server class that I
want to run in threads.

The way that you described it is the standard way to get around these
problems. The way I dealt with multiple threads is to simply have a base
class that deals with the SDL_CreateThread function and has the
sprite_callback functionality that you described. The base class has a
pure virtual “run” function that each thread overrides. It would mean
that you have to split your functionality out of one class and into
multiple classes. Normally that is not a problem since sperate threads
should avoid using the same data (variables) as much as possible. You
may also find that your class design makes more sense split out too.

AndyOn Tue, 2002-07-16 at 17:29, Nick Groesz wrote:

Nick Groesz wrote:

My particular problem is that I have 4 member functions within my
client class to be threaded and 4 member functions in my server
class
that I want to run in threads.

This would require a bunch of global functions that I would rather
not
pollute my code with. I am hoping someone here has a better idea as
to
how to get around this problem. My apologies if this is more of a
C/C++ programming question.

If you have lots of functions that look identical, you can often
generate them automatically with templates:

template<int (MyClass::* fn)()> class MyClassFunction {
public:
static int run(void *it)
{
return (static_cast<MyClass *>(it))->*fn();
}
};

SDL_CreateThread(MyClassFunctionMyClass::myFunction::run, (void
*)this);

Another is to pass the member functions pointer to the callback
(although this is somewhat difficult because of memory management
issues):

typedef int (MyClass::*member_function_t)();
typedef std::pair<member_function_t, MyClass *> callback_data_t;

int callback(void *raw_data)
{
callback_data_t *data = static_cast<callback_data_t *>(raw_data);
return data->second->(*data->first)();
}

call_back_data_t callback_data = std::make_pair(MyClass::myFunction,
this);
SDL_CreateThread(callback, (void *)(&callback_data));–
Rainer Deyke | root at rainerdeyke.com | http://rainerdeyke.com