c++

Efficiency between select() and recv with MSG_PEEK. Asynchronous

I would like to know what would be most efficient when checking for incoming data (asynchronously). Let's say I have 500 connections. I have 3 scenarios (that I can think of): Using select() to check FD_SETSIZE sockets at a time, then iterating over all of them to receive the data. (Wouldn't this require two calls to recv for each sock...

std::vector is so much slower than plain arrays?

I've always thought it's the general wisdom that std::vector is "implemented as an array," blah blah blah. Today I went down and tested it, seems to be not so: Here's some test results: UseArray completed in 2.619 seconds UseVector completed in 9.284 seconds UseVectorPushBack completed in 14.669 seconds The whole thing completed in 26....

Two questions on main

A. Is the following attempt valid to define the entry point 'main' of a C++ standalone program? namespace{ extern int main(){return 0;} } As far as I understand, it satisifies all the criteria about 'main' in the C++ standard (external linkage, available in global namespace because of the implicit using directive). So is this progra...

Fixing a weird write to file bug in c++

i got this really wierd problem, i'm writing my results to an output file, i use functions A B and C i activate them in that order, the results in the file is printed in a different order, first from A than from C and after that from B. i just can't understand why the results printed in a different order than the activation order. thanx....

Calling a function with variable number of arguments with an array in C++ (like python's * operator)

Hello world! I'm trying to write a v8 module in C++; there, the functions receive a variable number of arguments in an array. I want to take that array and call a function like gettext and printf that receives a formatted string and it's necessary args. The thing is, how can one take an array and send the elements as arguments to one of...

Make C++ call the right template method in an un-ugly way

I'm cooking up a vector library and have hit a snag. I want to allow recursive vectors (i.e. vec<H,vec<W,T> >) so I'd like my "min" and other functions to be recursive as well. Here's what I have: template<typename T> inline T min(const T& k1, const T& k2) { return k1 < k2 ? k1 : k2; } template<int N, typename T, typename VT1, typename...

create object based on time in c++

hi, i am writing a simulation about vehicle manufacturing, i am wondering how i can create objects based on time.. i have a base class Vehicle, and children Motorbike, Car, and Truck. 1 Motorbike will be manufactured every 1 hour, 1 car will be manufactured every 3 hours, and 1 truck will be manufactured every 8 hours. how can i create...

compressing socket send data

Hi, I'm trying to send a lot of data(basically data records converted to a string) over a socket and its slowing down the performance of the rest of my program. Is it possible to compress the data using gzip etc. and uncompress it at the other end? ...

File IO tricks using c/c++

Hi,Are there some good books or articles about file processing with c/c++, especially when the file is very large, GB or something like that? ...

Initializing static members of a templated class

I'm trying to figure out why this example doesn't compile. My understanding is that if a static variable is not explicitly set then it defaults to 0. In the five examples below four of them behave as I would expect, but the one that's commented out won't compile. #include <iostream> class Foo { public: static int i; static int ...

I have a c++ code that needs to be translated to c#, almost done (I think) but need help with P/Invoke to use an unmanaged dll

Hello, I'm having a hard time with a project (in c++.net) that needs to be converted to c#. This project uses an API written in unmanaged c++. I have the API´s .lib, .dll and .h, and want to call the dll functions from inside .net using p/invoke. Ok, here's the code: First, there is this c++ struct typedef struct { struct Item { ...

GLE 997:Overlapped I/O operation is in progress.

This post is related to my Previous Post. There I was creating the PipeServer and Client as two separate programme and was trying to write to the server and getting a response back.And the programme was going to an infinite loop. So for the sake of simplicity I combined both the Client and Server into a Single programme and run. Now I a...

boost::interprocess shared memory and R bigmemory

Hi, I have a server client system where the server is a vc++ program and the client is in R. Can I use a shared memory between these two? with boost::interprocess at the vc++ end and R bigmemory at the R end? the server and the client are on the same pc ...

Disproving ISO C++'s definition of function templates

A function template can be overloaded with other function templates and with normal (non-template) functions. A normal function is not related to a function template(i.e., it is never considered to be a specialization), even if it has the same name and the type as a potentially generated function template specialization. This is the...

What are the important features of C#

So, I am a C/C++ programmer currently in development of a small win32 project. I was told that C++ was becoming outdated, to be replaced with C#. This was over two years ago. So in your opinion, is C# a significant step up from C++, and does it provide more features/ease of use/ect.. that would make it worthwhile to learn. How much of ...

How to write such unit test?

Hi everyone, Now i'm expericing a problem about unit test, We have developed a platform with C++, and this platform include 2 layers, one is engine layer, the other one is widget layer, and i'm a dev in widget layer, The widget layer used by client app (those app is our product), now the problem is this: 1, We want to add some unit t...

Inserting an 'image' datatype value through SQL Query/C++

In the application I develop, the database table having a column of 'image' datatype. Now I want to insert the values into that table directly from my program, which is in VC++ 6.0, using a direct ExecuteQuery() of INSERT(due to performance considerations). The image column is been mapped to the structurre of the following declaration t...

generate random long number in C++

We know that to generate random long number we do following steps in Java Random r=new Random() return r.nextLong(); what will be equivalent of this code in C++? like this? return (long) rand(); ...

C++ global function

I declared a global function in a .cpp file void functionA(). I would like functionA() to be called exactly once before the start-up ( not inside main()). The thing I realize is if the function is int functionB(), I could call it using static int A = functionB(). But for return value of void, how could I do that? Thanks ...

How to write overload operators for STL containers and alogrithm functions?

For example, I want to write overload functions for set_difference which compares the type std::set<point> class myIter : public std::iterator<std::input_iterator_tag, int> { public: myIter(int n) : num(n){} myIter(const myIter & n) : num(n.num){} int & operator *(){return num;} myIter & operator ++(){++num; return *this...