Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Deffon
Mar 28, 2010

I have question regarding precompiled headers.

Let's say I have a number of source files: a.cpp, b.cpp and c.cpp.
I also have a precompiled header: d.pch which includes the big header file: e.h.

a.cpp includes e.h, so naturally it will compile faster, but what about b.cpp and c.cpp?

Will they compile a bit slower, and if so, is the size of the precompiled header affecting the time it takes for them to compile?

Adbot
ADBOT LOVES YOU

Deffon
Mar 28, 2010

Hot Yellow KoolAid posted:

I'm reviewing a practice exam for my Op Sys class, and I am having trouble answering some of the questions. They all concern semaphores, and I need to make sure I understand them.

The first one concerns the canonical Dining Philosophers problem (code):

Given the test method...

and the take_fork method...

What would be the effect of setting the philosopher's state to thinking after the two calls to the test() method in the take_fork() method? I've been staring at the code for over an hour and I've tried adding some diagnostic code, but so far I'm not really sure. The best I can figure is that it will cause the same philosopher to occasionally eat 2 or 3 times in a row.

I'm assuming that you mean the 'put_fork' method(since you quoted that part)?
If so, then the left and right philosophers will both try to eat if they are hungry. If so, they will fail, because the philosopher in question hasn't put down his forks yet.

Deffon
Mar 28, 2010

Paul MaudDib posted:

I basically have some code that iterates data, and several different simple payload functions that I want executed on them. I don't want to switch operations midstream, and I also don't want the overhead of making a function call. I basically just want to stick each payload into the function, compile it in turn, and give it a defined name, but without having the redundancy of the same iteration code being everywhere if I just copied and pasted five times.

So basically I want:
code:
void iterate_function(int * data, inline int func(int), int n);

inline int payload_a(int);

void deploy_payload_a(int * data, int n)
{
  iterate_function(data, payload_a, n);
}
How can I make that happen?

e: Perhaps prototype the payload and iteration functions, and then #define the deploy function? Would that inline it properly?
You need to inline iterate_function. As long as your payload functions are short and your not short on memory, this shouldn't be a problem.

Example:
code:
//iterate_function.h
inline void iterate_function(int * data, int (*func)(int), int n) {
	...
}

//payload_a.h
void deploy_payload_a(int * data, int n);

//payload.c
#include "iterate_function.h"

inline int payload_a(int) {
	...
}

void deploy_payload_a(int * data, int n) {
	iterate_function(data, payload_a, n);
}

Note that modern compilers are pretty smart about inlining, but if it refuses to inline your payload function on higher optimization levels, and it causes a bottleneck in your application, try a compiler specific extension (__attribute__((always_inline)) for gcc and __forceinline for msvc).

Deffon
Mar 28, 2010

^^
edit: fb.

In c++11 you can declare your handy signal like this:

code:
template<typename... Args>
using HANDY_SIGNAL = handy::arch::Signal<void(Args...)>;
And use it like this:
code:
HANDY_SIGNAL<IDrawable&, int, int> onSpriteMoved;
Don't think you could give names to the template parameters though.

Other than that, your macro solution can theoretically cause namespace scoping problems, but its probably not going to happen.

Deffon
Mar 28, 2010

If you want to keep the validation code as is, you could add a validation method to your registration entry class, and then iterate over the entries and validate them in main where you could catch their exceptions.

Deffon
Mar 28, 2010

Boron_the_Moron posted:

Ah, thank you.

I know this is the wrong thread, but would I be right in thinking that in order to split an object variable into its own unique object, I would need to use the "new" keyword, and copy the values of the original object into the new one?

If the object in question is a class instance (which you should prefer over struct instances in most cases), then yes.

Deffon
Mar 28, 2010

You can't really stop actively malicious users from modifying your objects anyway, since they can just reinterpret cast them. Exposing the member variables means that they will be shown as autocomplete suggestions for all usages of the class.

Adbot
ADBOT LOVES YOU

Deffon
Mar 28, 2010

Computer viking posted:


code:
structs = malloc(sizeof(struct) * i)
I think you meant to write "lines" instead of "i" here.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply