c++

Languages and Frameworks for creating High Load Web Service ?

Maybe, i'm duplicating some existing theme (close this one if it's true) but i'm planning to work with high load web services and curios about best practices. I have projects on Java and Grails. I'm doubt if Grails is right solution for high load service but Java (without any Hibernate or similar tools) can be used very well. Anyway, w...

boost::thread without all of boost?

is there a way to use boost's threading capabilities without the entire boost library? What are the bare minimum h and cpp files needed for this? Thanks ...

Can I use sizeof() or a #define for precision in sprintf of a string?

Lookign at: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/ for string (%.Ns) precision. When I use sizeof or a #define length in the precsion it reads it as actual text. Why is this? What are the rules of this? Does it have to be an integer value only? i.e. - buffer[50]; sprintf (buffer, "%.sizeof(buffer)s", stri...

High-performance message passing from C to Erlang

I have a C server (a data feed handler) that has the potential to send millions of tiny messages per second across a few thousand long-lived Erlang processes. In a single day, some of these processes will receive a few thousand messages, while others will receive tens of millions. My interests are threefold: to minimize latency — shor...

How to read successfully from a 2D texture

So I posted on Nvidia's forums (with no luck) and either 1. they just want to talk about how awesome graphics cards are or 2. My question is dumb so they don't look at it. (They don't look at my question in either case). Here's my question: How can I: Bind cudaMallocPitch float memory to a 2D texture reference Copy some host data to ...

Question regarding multithreading

I want to make a simple GUI API. Essentially the way it will work is the gui widget is basically a thread in an infinite loop. The thread has a pointer to the widget's class. The way I want it to work is basically similar to WinAPI. I would do something like this: textbox->SendMessage("Click",args); which is then added to its queue f...

How many bytes does a #define string (string literal) take?

#define STR "test1" Why does this take 6 bytes? sizeof(STR) = 6 ...

Converting c++ printf formatting to/from VB .NET string formatting

I have some VB .NET software that interfaces to a load of old (but sound) COM objects. The VB provides a GUI for the COM objects, part of which consists of setting various options on the COM objects - several of which relate to string formatting. I have a simple pair of VB .NET functions that convert basic %f, %d, %g formats to/from .NE...

Automated inlining for VC++?

Is there a way to tell the compiler to inline wherever it sees it to be useful? I thought it did this by default, but adding a few inline to my game loop functions improved performance by a good 30%. Thanks ...

Delete the current object and create an array of new ones

There is a member function which I would like to delete the current object and create an array of new ones in its place. How is it possible? The following code is an attempt of mine which has a lot of mistakes. void LernaeanHydra::split(int parts) { LernaeanHydra *new_heads = new LernaeanHydra[parts]; for (int i = 0; i < parts; ...

share a struct in c++ and c?

say a define a struct in header file of c++, foo.h typedef struct { ... }foo; in .c file I include the foo.h, then foo* fooPtr; will it work? ...

Can I use two precision '*' in a string format of two strings?

.* The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. #define SUFF ".txt" #define MAX_STR 50 fileName[MAX_STR]; name ="myFile" sprintf( fileName, "%s%s", name, SUFF ); //fileName = "myFile.txt" Now I want to bound the str...

Polymorphic STL compare function (class cmp class, class cmp int) for sorting

I'm implementing a game. I have a state tree and a set<> based priority queue that sorts the states on their costs. For this I have the < operator implemented as: struct DereferenceCompareState : public std::binary_function<State*, State*, bool> { bool operator()(const State* lhs, const State* rhs) const { verbose6("comparing ...

how do i solve a data conflict between string and inFile.open

#include<iostream> #include<fstream> #include<cstdlib> #include<string> using namespace std; **int main() { double write(); double read(); string choice; while(1) { cout<<"Enter read to read a file and write to write a file.\n"; cin>>choice; if (choice == "read") cout<< read(); if (c...

Opening a cash drawer using C/C++ or Java

I need to open a cash drawer using C/C++ or Java. It is a POS-X cash box with a USB connection. I've never done anything like this before. I noticed the cash box was linked to the "COM3" port. I know Java does not have a USB API so I turned to C/C++. ...

Virtual method & this pointer

Hi. I'm just beginning to learn C++ and I'm trying to make Thread class that that has the basic functionality of the Java Thread class. What I'm trying to do is make a class which you subclass, write a Run method (which is pure virtual in the base class) create an object of the subclass call the start method on it and you have thread. T...

C++, how to load images and count pixels of certain colours

Hi everyone, here's my problem: I'm looking for a way to import an image into C++ then traverse its pixels, incrementing a counter every time a pixel of a certain colour is found. I've done some research, but I haven't found anything particularly useful. DevIL looks like a good option, but I'm not sure where to start. Here's a bit of...

Using function pointers?

I'm not yet very familiar with these but maybe someone can shine light on this example. Imagine I have class CFoo and it will have a function to add a handler and a function which is a function pointer. So something like this: class CFoo { int *pointedFunc(int a, int b) = 0; void setFunc(int *func(int a, int b)) { pointedFunc = ...

are reference and pointer equal with regards to polymorphism

I always think of having to use pointers for polymorphism. Using the canonical example: DrawEngine:render(Shape *shape) { shape->draw(); shape->visible(true); } And passing in pointer to various Shape derived classes. Does it work the same with references DrawEngine:render(Shape &shape) { shape.draw(); shape.visible...

RapidXML XML parse error

I'm parsing an XML file which is quite simple: <?xml version="1.0" encoding="utf-8"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date> <description>An in-depth look at creati...