The key difference between memcpy() and memmove() is that memmove() will work fine when source and destination overlap. When buffers surely don't overlap memcpy() is preferable since it's potentially faster.
What bothers me is this potentially. Is it a microoptimization or are there real significant examples when memcpy() is faster so t...
I have a C++ code that's a physics simulation tool.
I would like to store some physical constants, conversion factor between different sets of units, and also some more application specific constants (such as definition like enum Planes {X=0, Y=1}) and I would like to be able to access them from everywhere in my code.
What would be th...
Hi everyone,
I'm using the following code (from MSDN) to rename a C++ thread:
#include <windows.h>
const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller ...
I have IInternetProtocol->Start method called and want to change HTTP request headers in there, but the rest of default implementation should be the same.
...
struct Base{
Base(Base &){} // suppress default constructor
};
struct Derived : Base{
};
int main(){
Derived d;
}
The code shown gives error because the default constructor (implicit) of 'Base' is suppressed. Indeed the standard says in $12.1 "If there is no user-declared constructor for class X, a default constructor ...
I have a code-base of legacy C/C++ code, which contains lots of functions that access global static variables, and are therefore not thread-safe. I'm looking for advice on how to convert this code to make it thread safe. It occurs to me that one way to do it would be to convert the static variables into thread-local variables, or otherwi...
Hi,
I'm trying to write a method that gets a vector of strings and returns a pointer to a random element. Can you please tell what is the problem with the following code?
string* getRandomOption(vector<string> currOptions){
vector<string>::iterator it;
it=currOptions.begin();
string* res;
int nOptions = currOptions.si...
I've got a Nvidia Tesla s2050; a host with a nvidia quadro card.CentOS 5.5 with CUDA 3.1
When i run cuda app, i wanna use 4 Tesla c-2050, but not including quadro on host in order not to lagging the whole performance while split the job by 5 equally.any way to implement this?
...
Hi!
I wonder if there is the "nicer" way of initialising a static vector than below?
class Foo
{
static std::vector<int> MyVector;
Foo()
{
if (MyVector.empty())
{
MyVector.push_back(4);
MyVector.push_back(17);
MyVector.push_back(20);
}
}
}
It's an example code...
I'd like to find all IPv6 addresses on all interfaces on a Linux server in a C++ program. I'm looking for the equivalent to GetAdaptersAddresses() on Windows.
I want to do the same as "ip -6 addr show" does. How "ip" do this ? strace didn't really enlighten me.
...
(not sure if it's only a C++ thing)
Exception handling is hard to learn in C++ and is certainly not a perfect solution but in most cases (other than some specific embedded software contexts) it's certainly the better solution we currently have for exception handling.
What about the future?
Are there other known ways to handle errors ...
Possible Duplicates:
Why does C++ need a separate header file?
In C++ why have header files and cpp files?
Hi geeks,
I have been using header files for almost everyday. It's kind of an instinct to me now. Suddenly, I ask myself, What on earth do we include a header file for?
Currently, I think of the following reason:
The...
Hi awesomes~
Currently I am writing some assembly language procedures. As some convention says, when I want to return some value to the caller, say an integer, I should return it in the EAX register. Now I am wondering what if I want to return a float, a double, an enum, or even a complex struct. How to return these type of values?
I c...
I have the following function:
int mult(int y, int z)
{
if (z == 0)
return 0;
else if (z % 2 == 1)
return mult(2 * y, z / 2) + y;
else
return mult(2 * y, z / 2);
}
What I need to do is prove its correctness by induction. Now the trouble I'm having is that even though I know it works since I ran it I can't follow eac...
Hello everybody.
I am using visual studio 2008 for developing. My program needs to deal with a huge amount of memory. The error happens when my program try to allocate a 512M float array. Code is the following:
int size = 512*512*512;
float *buffer = new float[size];
Before this allocation, the program already consumed around 554M me...
What's the difference on the VC++.net complier (cl.exe /EHsc) and the GCC compiler, compiling, let's say this program:
#include <iostream>
using namespace std;
int main(){
unsigned int test;
cin >> test;
cout << test;
return 0;
}
I know that the vc++ compiler compiles to an exe, and gcc is compiling to the linux executable, and t...
Hey all,
I'm working on a Firefox NPAPI plugin + XPCOM component. I've run into a dilemma: Given a file downloaded from the Internet (say a PDF or PNG) how do I start the default helper application to display that file on Linux using C/C++?
Currently I'm using the system function call to invoke the gnome-open command and passing it the...
How can I get the system language in C/C++? Like en_US or en_GB.
...
I'm a relative noob to installing libraries. My system currently has an older version of the ICU library (3.8) and I want to go the latest (4.4).
Following the steps in the ICU readme.html, everything goes fine (echo $? produces all 0 for every step). And I see the libary was installed to /usr/local/lib. However the current version of t...
I want to mock a method with the declaration A::B X(void). The definition is something as follows.
class A {
class B;
virtual B X() = 0;
};
class A::B {
public:
auto_ptr<int> something;
};
My mock class, following this, is quite standard.
class mA : public A
{
public:
MOCK_METHOD0(X, A::B());
};
Compiled, howev...