c++

Performance of Win32 memory mapped files vs. CRT fopen/fread

I need to read (scan) a file sequentially and process its content. File size can be anything from very small (some KB) to very large (some GB). I tried two techniques using VC10/VS2010 on Windows 7 64-bit: Win32 memory mapped files (i.e. CreateFile, CreateFileMapping, MapViewOfFile, etc.) fopen and fread from CRT. I thought that mem...

A std::map like container that maps types to values.

I'm looking for a hybrid meta-container/container class. I want a class that maps a compile-time type to a runtime value. A code snippit is worth 1024 words so: struct Foo { /* ... */ }; struct Bar { /* ... */ }; int main() { meta_container<Foo,float,int> mc; mc.get<float>() = 1.0f; mc.get<Foo>().method(blah); mc.get<Bar>...

Command line switches out of order

Hey all - I'm working on a C++ program that accepts a filename as a command line input, reads a bunch of data from that file, computes two things about the data, then exits. One of those computations must be done, but the other is much more optional, so I thought it would be neat to add a -c flag to turn it off. Naively, I would just a...

Inheriting problems

class Base { private: int var; }; class Child : protected Base { void someFunc() { var = 5; // Error: Base::var is private } }; What's wrong is there? ...

Expanding a dynamically allocated array

I have allocated an array as follows. #include <iostream> int main() { const int first_dim = 3; const int second_dim = 2; // Allocate array and populate with dummy data int** myArray = new int*[first_dim]; for (int i = 0; i < first_dim; i++) { myArray[i] = new int[second_dim]; for (int j = 0; j < se...

Block attatchment in 3D grid

I'm doing ray picking to find the scene node that my cursor points at. All of those scene nodes are equally sized cubes. I have the hit scenenode's position, the position of the ray intersection and the triangle that the node/mesh that were hit. What i want to do is to attatch a new block to the face of the collided scenenode block that ...

Is a friend function defined in-class automatically inline?

If a member function is defined inside the class, it is an inline function. E.g. struct X { void mem_f() {} //mem_f is inline }; My question is whether a nonmember friend function defined inside the class is also automatically inline. E.g. struct Y { friend void friend_f() {} //is friend_f inline? }; A relevant quote/para...

Create file/folder structure in VS 2010

Hello. I am somewhat of a novice and am seeking some help. I am working in Visual Studios 2010 and have my solution that has my project that I am currently working on. Specifically I am working on a Win32 Project. I don't know if that is important to know or not. I have made a file/folder structure in the directory I am working on to h...

Cyclic and acyclic data structures

What is the difference, can you give me examples, thanks in advance ...

Derived class function

class Base { protected: int data; public: virtual int getData() { return data; } virtual void setData(int value) { data = value; } }; class Child : protected Base { public: void setData(int value) { Base::setData(value); cout << "Data is set.\n"; } }; class Worker { private: C...

Why is my MD5 value printing with extra "f" characters?

I have strange problem when using at() method of std::string. I'd like to calculate md5 hash for given string using this library: http://sourceforge.net/projects/libmd5-rfc/files/ Hash is calculated correctly, but there is a problem with printing it human way. The output is: af04084897ebbf299b04082d105ab724 ffffffaf040848ffffff97ffffffe...

Type decision based on existence of nested typedef.

I need to define a template struct such that: element<T>::type is of type: T::element_type if T contains a (public) typedef named element_type, otherwise (if it does not contain such typedef) element<T>::type is of type T::value_type if T is mutable and of type const T::value_type if T is constant. I am really strugglin...

OpenGL: Triangles with points at infinity

I am trying to render a two-dimensional half-plane in OpenGL with the following code: void renderHalfplane(double *x, double *n) { glPushMatrix(); double theta = -360.0 * atan2(n[0], n[1])/(2.0*PI); glTranslated(x[0], x[1], 0); glRotated(theta, 0, 0, 1.0); glBegin(GL_TRIANGLES); glVertex4d(0.0, 0.0, 0.0, 1.0); glVertex4d...

Passing a boost::unordered_set as the result map to boost::split

Does anyone know if it's kosher to pass a boost::unordered_set as the first parameter to boost::split? Under libboost1.42-dev, this seems to cause problems. Here's a small example program that causes the problem, call it test-split.cc: #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/split.hpp> #in...

c++ error C3200

hello! I'm struggling with compile error C3200 http://msdn.microsoft.com/en-us/library/3xwxftta.aspx discusses the problem and gives as an example: // C3200.cpp template<typename T> class X { }; template<template<typename U> class T1, typename T2> class Y { }; int main() { Y<int, int> y; // C3200 } and suggests that instead ...

Is there a microsoft API that to check whether a given IP address has access to an smtp connector in Microsoft Exchange?

I would like to be able to check, programmatically in c++, as simply as possible whether a given ip address has access on an SMTP connector. In MS exchange management console you can check this from the "receive mail from remote servers that have these IP addresses:" section of the SMTP connector properties->Network. So far the best I ...

How to free the memory of Task& a=*new(task::allocate_root()) P2MainTask(&Improve)?

I originally built my TBB code on Windows and it worked fine. Today I moved my code to Linux system (OpenSUSE 64 bit). When I tried to run it, the program always stopped after some iterations. I wonder whether it is because the system run out of memory.The part of code is put below. SolverP2 Improve(&inst,&mysolution,StartSolT1,&P1Queu...

ifstream fails to open in recursive calls

hello. we are running into an odd issue when trying to parse an input file. the idea is that this file can include other files, which must be parsed as well. We are doing this recursively in a function defined as int parse_inp(const char* filename) The main file parses no problem, but recursive calls cannot open their file streams. ...

Game Development, the language for beginners?

I have been searching through the website looking for the best language for beginner game development. Many people say a C based language, others suggest Python. Normally I would just pick one, but this is my dilemma. I am not sure if this is correct, but I read from programmers on here that C is much faster at 3d render, whereas Python...

Code requires too much memory

Hello, I'm porting some code to another structure: class EnvironObject { protected: vector<float> mX, mY, mXSpeed, mYSpeed; int mMaxObjects; public: virtual void init(int maxObjects); virtual void setLimit(int limit); virtual int getLimit(); virtual void update(float arg) = 0; }; void EnvironO...