In the following example (Chapter 2), Anthony Williams is trying to parallelize the standard accumulate function. my question is why is he doing this:
unsigned long const max_threads=(length+min_per_thread-1)/min_per_thread;
why add length and subtract 1?
why not just:
unsigned long const max_threads=length/min_per_thread;
....
Hello, I want to localize a program I already written.. It's fairly big (almost 50k lines) and ideally I want a system that allows me (the programmer) to do the least amount of work possible, and without major changes to the program - if possible none at all.
I looked at gettext() and liked it a lot, but it's unclear to me how it would ...
I've been using VS2005 and VS2008 now for a while, with C#. Without any additional tools I could hit ctrl k + d and the code would nicely reformat. Why doesn't C++ do this?
It's the same Visual Studio after all. Is there a way to enable it?
A second part of this question is related, for those who've been using resharper with C#, is the...
EDIT: Just to make things clear, this problem was caused by a typo in my code,
in
pointer = new BYTE(datasize);
should have been
pointer = new BYTE[datasize];
All is well!
END
Hi!
I'm having a weird stack overflow problem in Visual Studio 2005 in a C++ project..
In my code, I have a
BYTE* pointer;
This pointer is set to NU...
I have finally worked out how to get stdin and stdout to pipe between the main app and a process created with CreateProcess (win32) or exec (linux). Now I am interested in harnessing the piping nature of an app. The app I am running can be piped into:
eg: cat file.txt | grep "a"
If I want to run "grep", sending the contents of "file...
I am curious about the impact my typedef approach has on my builds.
Please consider the following example.
#include "SomeClass.h"
class Foo
{
typedef SomeClass SomeOtherName;
SomeOtherName* storedPointer;
void setStoredPointer(SomeOtherName* s);
}
void Foo::setStoredPointer(SomeOtherName* s)
{
storedPointer = s;
}
...
I need to gain access to the list of most recently used programs and list of recently opened files in Windows OS programatically. These are the items you generally see once you click start in windows. I am looking to use C# but if its better in Managed C++ I will do that too.
...
I am trying to calculate a determinant using the boost c++ libraries. I found the code for the function InvertMatrix() which I have copied below. Every time I calculate this inverse, I want the determinant as well. I have a good idea how to calculate, by multiplying down the diagonal of the U matrix from the LU decomposition. There i...
I've been playing with C++ for a few years now, and want to become adept at using
and factories. Are there some good web tutorials and/or textbooks that cover this well?
I started programming prior to the wide use of the term "patterns" ('80's)... but when I first saw the term I recognized the "pattern" of it's usage. A good referenc...
Hi..
I have a transparent rectangle on a picture box,if i click next,the next image comes and transparent rectangle is drawn.The problem is flickering,while moving from one image to another image,the transparent rectangle flickers.please help me how to get rid of this problem.i want to eliminate flicker,please help.
Thanks
...
I am aware that casting ints to floats (and vice versa) is fairly expensive. However, does the compiler automatically do it at compile time for constants in your code? For e.g. is there any difference between
float y = 123;
float x = 1 / y;
and
float y = 123.f;
float x = 1.f / y;
I see some code that does the latter, but I'm not su...
Hello,
I would like to compare two objects through their addresses. I tried operator overloading and it does not seem to work for pointers, but works for objects themselves. The following is the relevant code:
class C {
public:
int x;
};
.
.
.
bool operator <( C *ptr_c1, C *ptr_c2 )
{
return ( (*ptr_c1).x...
After reading this article on thedailywtf.com, I'm not sure that I really got the joke.
It says there that some guy changed the code from
int function()
{
int x;
char data_string[15];
...
x = 2;
strcpy(data_string,"data data data");
...
}
to
int function()
{
int x = 2;
char data_string[15] = "data data data";
.....
Hi,
I'm writing some code that looks like this:
while(true) {
switch(msg->state) {
case MSGTYPE: // ...
break;
// ... more stuff ...
case DONE:
break; // **HERE, I want to break out of the loop itself**
}
}
Is there any direct way to do that?
I know I can use a flag, and break from the loop by pu...
I'm trying to read contents of a game's map/model files into a program for the purposes of writing a small model viewer and testing out some DirectX features. The model/map file formats are chunked in nature, and I know the format of these files. I can easily read the files by parsing through the individual chunks, using an approach like...
Using MinGW through Eclipse for C/C++, and attempting to get GLUT (OpenGL Utility Toolkit) working on it, but I suspect it's a simple problem.
Attempts to build result in:
g++ -LC:\Documents and Settings\C\workspace\GLUTtest\Debug -LC:\Tools\MinGW\include\GL -LC:\Tools\MinGW\include -oGLUTtest.exe main.o -lglut32.lib
C:\Tools\MinGW\bi...
I have an array of uint64 and for all unset bits (0s), I do some evaluations.
The evaluations are not terribly expensive, but very few bits are unset. Profiling says that I spend a lot of time in the finding-the-next-unset-bit logic.
Is there a faster way (on a Core2duo)?
My current code can skip lots of high 1s:
for(int y=0; y<hei...
I'm writing a DLL in Delphi using the below C++ example:
USERDLL_API double process_message (const char* pmessage, const void* param)
{
if (pmessage==NULL) { return 0; }
if (param==NULL) { return 0; }
if (strcmp(pmessage,"state")==0)
{
current_state *state = (current_state*) param;
return process_state( (cu...
Is the following code legal?
char* randomMethod1() {
char* ret = "hello";
return ret;
}
and this one?
char* randomMethod2() {
char* ret = new char[10];
for (int i = 0; i < 9; ++i) {
ret[i] = (char)(65 + i);
}
ret[9] = '\0';
return ret;
}
I'd say the first one is legal, as what you are actually...
I was wondering where I can download a c++ compiler with code completion that doesn't suck like the back-end of a donkey. I have tried Eclipse, but that could not find code that had a space in the path (which means the entire concept is kinda unless), I tried codeblocks, which has a limited form of code completion that can only list the ...