c++

How to avoid running out of memory in high memory usage application? C / C++

I have written a converter that takes openstreetmap xml files and converts them to a binary runtime rendering format that is typically about 10% of the original size. Input file sizes are typically 3gb and larger. The input files are not loaded into memory all at once, but streamed as points and polys are collected, then a bsp is run on ...

qpThreads documentation

Is there any documentation on qpThreads? In what way is it different from pthreads? ...

Simple OpenGL texture map not working?

I'm trying to figure out texture mapping in OpenGL and I can't get a simple example to work. The polygon is being drawn, though it's not textured but just a solid color. Also the bitmap is being loaded correctly into sprite1[] as I was successfully using glDrawPixels up til now. I use glGenTextures to get my tex name, but I notice it ...

C memset seems to not write to every member

I wrote a small coordinate class to handle both int and float coordinates. template <class T> class vector2 { public: vector2() { memset(this, 0, sizeof(this)); } T x; T y; }; Then in main() I do: vector2<int> v; But according to my MSVC debugger, only the x value is set to 0, the y value is untouched. Ive never used si...

Operator = Overload with Const Variable in C++

Hi everybody. I was wondering if you guys could help me. Here are my .h: Class Doctor { const string name; public: Doctor(); Doctor(string name); Doctor & Doctor::operator=(const Doctor &doc); } and my main: int main(){ Doctor d1 = Doctor("peter"); Doctor d2 = Doctor(); d2 = d1; } I want to ...

Using local classes with STL algorithms

I have always wondered why you cannot use locally defined classes as predicates to STL algorithms. In the question: Approaching STL algorithms, lambda, local classes and other approaches, BubbaT mentions says that 'Since the C++ standard forbids local types to be used as arguments' Example code: int main() { int array[] = { 1, 2, ...

C/C++ Registry Help

I am programming an mp3 application, and I have it so it starts on start up. However when looking at it in msconfig it says manufacturer is unknown. How can I make it say "daxsoft"? Is there a a way to do this without a .rc file? ...

Convert iterator to pointer?

I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function. For example, my vector<int> foo contains (5,2,6,87,251). A function takes vector<int>* and I want to pass it a pointer to (2,6,87,251). Can I just (safely) take the iterator ++foo.begin(), convert it to a pointer...

Tiling texture bmp file as texture onto a rectangle in OpenGL?

I have a pic.bmp that I'm attempting to tile onto a 3 x 2 rectangular flat surface for a demo I'm making. I'm attempting to keep the aspect ratio of the bmp in tact but I still want to tile it across that surface. Right now I have the surfaces vertices as (0,0,0), (3,0,0), (0,2,0) and (3,2,0). How can I apply this bmp to the flat surf...

How to Parse Lines With Differing Number of Fields in C++

I have a data that looks like this: AAA 0.3 1.00 foo chr1,100 AAC 0.1 2.00 bar chr2,33 AAT 3.3 2.11 chr3,45 AAG 1.3 3.11 qux chr1,88 ACA 2.3 1.33 chr8,13 ACT 2.3 7.00 bux chr5,122 Note that the lines above are tab separated. Moreover, it sometime may contain 5 fields or 4 fields. What I want to do is to capture 4th fields in...

size() Vs empty() in vector - why empty() is preferred?

While debugging something, I saw the STL vector::empty() implementation: bool empty() const {return (size() == 0); } I believe, whenever we are probing the emptiness of vector it is always recommended to use empty over size(). But seeing that implementation, I am wondering, what is the benefit of doing so? Instead, there is a fun...

Accessing static class variables in C++?

Duplicate: C++: undefined reference to static class member If I have a class/struct like this // header file class Foo { public: static int bar; int baz; int adder(); }; // implementation int Foo::adder() { return baz + bar; } This doesn't work. I get an "undefined reference to `Foo::bar'" error. How do I access stati...

Is it good to send stack allocated object as a pointer parameter to some other function?

Is it good to send stack allocated object as a pointer parameter to some other function? ...

How to refactor a class in C++ to make a certain function const?

I have a class which looks something like this: class MyClass { public: // some stuff omitted /*** A function which, in itself, is constant and doesn't change the class ***/ void myFunction( void ) const; private: /*** If loaded is true, then internal resources are loaded ***/ boolean loaded; }; Because I desig...

Tool Chain for WxWidgets explained

Where can I find an writeup that shows me how to set up a tool chain for WxWidgets (C++) on linux/ubunto and/or OS X. I downloaded, compiled & installed WxWidgets both on linux and OS X, compiled and tried the samples, but seem to be stuck setting up a compile environment in my own home directory. DialogBlocks from http://www.dialogblo...

How does const correctness help write better programs?

This question is from a C# guy asking the C++ people. (I know a fair bit of C but only have some general knowledge of C++). Allot of C++ developers that come to C# say they miss const correctness, which seems rather strange to me. In .Net in order to disallow changing of things you need to create immutable objects or objects with read o...

C++ Implementation of a Binary Heap

I need a min-heap implemented as a binary tree. Really fast access to the minimum node and insertion sort. Is there a good implementation in stl or boost that anyone can point me too? ...

Are inline functions in C/C++ a way to make them thread-safe?

I make the following reasoning, please tell me what's wrong (or right) about it: "If inlining a function duplicates the code in the place the function is called, then the static and local variables are duplicated for each function calling it and if there is only one thread running the function that calls the inlined one at the same time...

What is the exact definition of instance variable?

For me instance variables are simple data types like int or double. Everything that is created automatically when the object is created. If an object creates additional objects - like everything that is it done with the NEW keyword - these are not instance variables. Am I right or wrong? ...

About the MSDN Documentation on NOTIFYICONDATA's cbSize member

I am reading the NOTIFYICONDATA documentation in MSDN. It says the NOTIFYICONDATA structure has a cbSize member should be set to the size of the structure, but NOTIFYICONDATA structure's size has different size in every Shell32.dll, so you should get the Shell32.dll version before setting cbSize. The following quotes from MSDN: If i...