c++

Efficiency of the STL priority_queue

I have an application (C++) that I think would be well served by an STL priority_queue. The documentation says: Priority_queue is a container adaptor, meaning that it is implemented on top of some underlying container type. By default that underlying type is vector, but a different type may be selected explicitly. and Priority...

Reading in 4 bytes at a time

I have a big file full of integers that I'm loading in. I've just started using C++, and I'm trying out the filestream stuff. From everything I've read, it appears I can only read in bytes, So I've had to set up a char array, and then cast it as a int pointer. Is there a way I can read in 4 bytes at a time, and eliminate the need for ...

Should a programmer have mastery over C++

I was wondering if it is necessary for programmers to have expertise on at least 1 programming language? Programming languages like C#, java, VB.Net etc change every year or two. Should a programmer have mastery over C++, which is a stable language and rarely undergoes changes? I am a C# developer and using it for about 7 years now,...

Force OpenGL to keep contents in memory?

I'm using OpenGL to render polygons. I notice that if I minimize the program then start using it again, it will be very slow for a few seconds. (I'm guessing its reuploading my display lists to the card). How can I prevent this because it's a bit annoying. I want it to always have the contents. Thanks ...

Visual C++ Compiler allows dependent-name as a type without "typename"?

Hello, Today one of my friends told me that the following code compiles well on his Visual Studio 2008: #include <vector> struct A { static int const const_iterator = 100; }; int i; template <typename T> void PrintAll(const T & obj) { T::const_iterator *i; } int main() { std::vector<int> v; A a; PrintAll(a); PrintAll(v); ...

[Qt] Limits of the resource system

Hi, My Qt application depends on Oracle DLLs to start. As it's linked statically for the most part (except for these DLLs), I'd like to embed the DLLs and the EXE into a launcher that would behave like a fully static application (one exe, no DLLs to take along). The launcher would extract the included files in a temp directory, launc...

How to create a function with return type map<>?

Fairly straightforward question. I have a map that I wish to initialize by calling a function like so: map<string, int> myMap; myMap = initMap( &myMap ); map<string, int> initMap( map<string, int> *theMap ) { /* do stuff... */ However, the compiler is moaning. What's the solution to this? EDIT 1: I'm sorry, but I screwed up....

ExecuteExcel4Macro on custom xll functions

I have a C++ .xll addIn for Excel. The following test worksheet function works fine with the xll loaded: LPXLOPER __stdcall Test() { return &xlstring("Yayage",true) } i.e. =Test() returns "Yayage" in the worksheet. xlstring is my own custom method which turns a string into an excel string and specifies whether excel or the xll are...

Error can not open source file "..."

Busy day today; asking more questions than usual... anyway.... I'm using VS2010 (downloaded via dreamspark) and although I can open the #include file by right clicking on it and pressing on Open Document, it complains "Error can not open source file "..."" which seems rather absurd. I'm using Qwt with Qt this time around and I'm specifi...

C++ Refactoring Precompiled Header

Unfortunately on a project here at work, someone had the great idea to put every header every single file from pretty big project into the precompiled header. This means any change to any header in the project has to recompile the entire project, and all cpp files taking way too long. Is there any decent C++ refactoring tool which coul...

c++ project using c# assemblies: how to speedup compile time?

I've got a mixed c++/c# project. The original project is c++ and has been extended using c# assemblies. In the beginning this was ok, but since the c# part is growing I experience a big problem growing: Compile time of the c++ part becomes a problem. Why? Simple: every time I change something in a c# project, the c++ compiler is not su...

C++ Constructor Parameters Question

Hi, I'm learning C++. I have a simple class named GameContext: class GameContext { public: GameContext(World world); virtual ~GameContext(); }; To initialize a GameContext object, I need a World object. Should the GameContext constructur take a pointer to a World object (World*), the address to a World object (&...

C++0x threading

With the advent of threading facilities in the STL for the new C++ standard (C++0x), will it be better to change existing code that is using POSIX threading or even Windows threading to use STL threading? ...

How large does a collection have to be for std::map<k,v> to outpace a sorted std::vector<std::pair<k,v> >?

How large does a collection have to be for std::map to outpace a sorted std::vector >? I've got a system where I need several thousand associative containers, and std::map seems to carry a lot of overhead in terms of CPU cache. I've heard somewhere that for small collections std::vector can be faster -- but I'm wondering where that line...

Qt Creator XOpenDisplay undefined reference

Now I am feeling quite stupid. I am trying to do some stuff with xlib in Qt Creator. My code: #include <QtCore/QCoreApplication> #include <X11/Xlib.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Display *display = XOpenDisplay(NULL); return 0; } Just one line of code and gives me: /main.cpp:8: u...

porting kde application to windows

hy I'm trying to port a KDE application to windows my problem is finding a suitable KDE SDK for windows, i can't include any k-headers (kapplication.h kaction.h ....) and I haven't even got to the libs is there a guide for doing things like this ...

How do you indent preprocessor statements?

When there are many preprocessor statements and many #ifdef cascades, it's hard to get an overview since normally they are not indented. e.g. #ifdef __WIN32__ #include <pansen_win32> #else #include <..> #ifdef SOMEOTHER stmts #endif maybe stmts #endif When I consider also indenting those preprocessor statements, I fear of getting conf...

Why does my data not seem to be aligned?

I'm trying to figure out how to best pre-calculate some sin and cosine values, store them in aligned blocks, and then use them later for SSE calculations: At the beginning of my program, I create an object with member: static __m128 *m_sincos; then I initilize that member in the constructor: m_sincos = (__m128*) _aligned_malloc(Bins...

atomic swap with CAS (using gcc sync builtins)

Can the compare-and-swap function be used to swap variables atomically? I'm using C/C++ via gcc on x86_64 RedHat Linux, specifically the __sync builtins. Example: int x = 0, y = 1; y = __sync_val_compare_and_swap(&x, x, y); I think this boils down to whether x can change between &x and x; for instance, if &x constitutes an op...

Integer Types in file formats

Hi, I am currently trying to learn some more in depth stuff of file formats. I have a spec for a 3D file format (U3D in this case) and I want to try to implement that. Nothing serious, just for the learning effect. My problem starts very early with the types, that need to be defined. I have to define different integers (8Bit, 16bit, 3...