c++

How to get available memory C++/g++ ?

I want to allocate my buffers according to memory available. Such that, when I do processing and memory usage goes up, but still remains in available memory limits. Is there a way to get available memory (I don't know will virtual or physical memory status will make any difference ?). And method has to be platform Independent as its goin...

bitwise not operator .

Why bitwise operation (~0); prints -1 ? In binary , not 0 should be 1 . why ? ...

C vs. C++ for performance in memory allocation

Hi, I am planning to participate in development of a code written in C language for Monte Carlo analysis of complex problems. This codes allocates huge data arrays in memory to speed up its performance, therefore the author of the code has chosen C instead of C++ claiming that one can make faster and more reliable (concerning memory leak...

More inside an IDE(eclipse cdt)

This is what I see in the Console when I clicked Project->Clean menu: g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hw.o ..\src\hw.cpp g++ -ohw.exe src\hw.o But I've no idea how is these command generated? Can someone elaborate the lifecycle of the command? This is the .project file: <?xml version="1.0" encoding="UTF-8"?> <projectD...

How can I handle weird errors from calculating acos / sin / atan2?

Has anyone seen this weird value while handling sin / cos/ tan / acos.. math stuff? ===THE WEIRD VALUE=== -1.#IND00 ===================== void inverse_pos(double x, double y, double& theta_one, double& theta_two) { // Assume that L1 = 350 and L2 = 250 double B = sqrt(x*x + y*y); double angle_beta = atan2(y, x); dou...

Iteration through std containers in openmp

Hi, people. I try to use openmp for multithreading the loop through std::set. When I write the following code - #pragma omp parallel for for (std::set<A>::const_iterator i = s.begin(); i != s.end(); ++i) { const A a = *i; operate(a); } I get an error - error: invalid type for iteration variable 'i...

How to update a uniform variable in GLSL

Hi All, I am trying to get update the eye position in my shader from my appliaction but I keep getting error 1281 when I attempt this. I have no problems after the initialization just when i subsequently try to update the values. Here is my code: void GraphicsObject::SendShadersDDS(char vertFile [], char fragFile [], ...

[C++] Run codes for only 60 times each second.

Hello there, I'm creating a directx application that relies on the system time (because it must be accurate), and I need to run lines of code for 60 times each second in the background (in a thread created by boost::thread). that's equal to 60 FPS (frame per second), but without depending on the main application frame rate. //............

How to modify Registry of window OS from c or c++

I want to modify the registry of window OS using c. kindly guide me or give me some hints so that I can make it possible. ...

How to directly access a certain part of a text file in g++?

I have a text file containing a number of records. Each record is stored on a single line that is 100 characters long. Let's say I want to directly access the nth record. I could do it using a for loop, reading in n lines until I get to the record. But how could I access it directly? ...

My listview is not gaining the keyboard focus in Qt

Hi, i am trying to operate the listview itesm through keyboard focus, its not moving.. can you folks suggest where i am wrong. if i click on the listview from mouse, listview is gaining the focus. i dont no what is wrong. class Newlist : public QWidget { public: Newlist(QWidget *parent = 0); ~Newlist(){}; public: QListVi...

Scalable memory allocator experiences

I am currently evaluating a few of scalable memory allocators, namely nedmalloc and ptmalloc (both built on top of dlmalloc), as a replacement for default malloc / new because of significant contention seen in multithreaded environment. Their published performance seems to be good, however I would like to check what are experiences of ot...

C++ IDE for Linux with smart reference searching

Is there an IDE supporting C++ with REALLY smart searching of references? By 'reference' I mean usage of a class (or its member), variable, function in the whole Project or Workspace. There's lots of IDE providing it. Some of them seem just to search for the text with same name giving lots of stuff, others are smarter and check the cont...

Error while calling a virtual function

I have an error while calling a virtual function that is defined in Derived class but not present in Base class? Why this error when I have pointer pointing to derived class? #include<iostream.h> class A{ public: virtual void fun() {cout<<"A::fun()"; } }; class B : public A { public: virtual void fun() {cout<<"B::fun()"; } virtual v...

Understanding extern in c++

namespace std { extern istream cin; ... } By using extern we declare that cin is defined in some other unit as the answer But what if istream is defined/undefined in std,there should be some difference,right? What is the difference for the compilor? ...

Declare module name of classes for logging

I currently am adding some features to our logging-library. One of these is the possibility to declare a module-name for a class that automatically gets preprended to any log-messages writing from within that class. However, if no module-name is provided, nothing is prepended. Currently I am using a trait-class that has a static function...

Getting name and type of a struct field from its object

For example, I have a struct which is something like this: struct Test { int i; float f; char ch[10]; }; And I have an object of this struct such as: Test obj; Now, I want to programmatically get the field names and type of obj. Is it possible? This is C++ BTW. ...

How to get a filetype icon in Windows using C/C++?

I am looking for a C/C++ code which can get icon for a given filetype (eg. .doc, .pdf) on Windows. I need to make an application which will display a list of files and I need to have the file icons corresponding to those files. I have seen C# code for the same but I have never worked with C# and don't think that I can use the same code ...

Is it a good idea to return " const char * " from a function?

Now I have a function that has to return a string. I saw a particular implementation where he returns a const char * from the function. Something like this: const char * GetSomeString() { ........ return somestlstring.c_str(); } SomeOtherFoo () { const char * tmp = GetSomeString(); string s = tmp; } Now I felt there is...

Is there any reason for a blocking call to winsock send() function on Vista to return immediately ?

Hi All, Is there any reason for a blocking call to winsock's send() function on Vista to return immediately ? It works with expected delay on XP and below. I'm wondering if this has got anything to do with auto-tuning feature of Vista. Code: char *pBuffer; // pointer to data int bytes; // total size int i = 0, j=0; w...