c++

portable threading APIs

Hi all, I know of three portable threading C++ APIs : Qt boost::thread GNU Pth Apart from possible licensing issues involved, how do these compare in: actual portability (mostly interested in Linux and Windows) capabilities programming ease-of-use support/development activity of the library And: are there more like these that a...

how to use Exceptions in C++ program?

hey , i am trying to inherit the exception class and make a new class called NonExistingException: i wrote the following code in my h file: class NonExistingException : public exception { public: virtual const char* what() const throw() {return "Exception: could not find Item";} }; in my code before i am sending something t...

Thread synchronization with boost::condition_variable

Hello, I'm doing some experiments on C++ multithreading and I have no idea how to solve one problem. Let's say we have thread pool, that process user requests using existing thread and creates new thread, when no free thread available. I've created command_queue thread-safe class, which have push and pop methods. pop waits while queue i...

What is the meaning of "difference of memory address?"

Consider #include <cstdio> int main() { char a[10]; char *begin = &a[0]; char *end = &a[9]; int i = end - begin; printf("%i\n", i); getchar(); } #include <cstdio> int main() { int a[10]; int *begin = &a[0]; int *end = &a[9]; int i = end - begin; printf("%i\n", i); getchar(); } #...

Is there a general smart pointer like auto_ptr and shared_ptr that doesn't need C++0x?

I'm wanting a non-reference counted smart pointer that can combine some of the useful aspects of auto_ptr and shared_ptr. I think that C++0x's unique_ptr is ultimately what I'd need, but I need something that will compile on Visual Studio 2008 and Xcode (gcc 4.2). The functionality I need is: Usable in factory methods so that owners...

Adding message to assert

Hallo! I'm looking for a way to add custom messages to assert statements. I found this questions http://stackoverflow.com/questions/3692954/add-custom-messages-in-assert but the message is static there. I want to do something like this: assert((0 < x) && (x < 10), std::string("x was ") + myToString(x)); When the assertion fails I wan...

Fast $MFT parsing - library

I'm need to read(simple and already done) and psrse the $MFT - gather files $DATA runs and file names, time stamps and so on.. I have started with this ntfs library, but it is too slow to scan the entire mft. How can I speed it up or is there another - more faster library? Thanks, but could you please explain to me why the following co...

Mixing component based design and the model-view(-controller) pattern

'm developing a 2D game and I want separate the game engine from the graphics. I decided to use the model-view pattern in the following way: the game engine owns game's entities (EnemyModel, BulletModel, ExplosionModel) which implement interfaces (Enemy, Bullet, Explosion). The View receives events when entities are created, getting th...

Character sets - Not clear

The standard defines -basic source character set -basic execution character set and it's wide char counterpart It also defines 'execution character set' and it's wide char counterpart as follows $2.2/3- "The execution character set and the execution wide-character set are supersets of the basic execution character set and th...

Deleting objects from template list

Hi All, I have a template list say, List<SuperClass*>* mList; for(int i = 0;i < mList->ElementsCount();i++) mList->DeleteElementAtIndex(i); in mList objects of subclasses are added. while on deleting object from the list, should i need to convert the object into corresponding subclasses and call delete method ...

what is the default operation of '=' operator?

Hi I have a class Number which represents a double with 2 digits after the dot. Before I overloaded the = operator i ran some tests and got confused a little: int main(int argc, char **argv) { Number *w = new Number(1.111); Number *q = new Number(3.444); *w = *q; std::cout << w->GetNumber() <<std::endl; delete q; ...

lifetime of declaration within a loop

Hi, I have a loop as follows while(1) { int i; } Does i get destroyed and recreated on the stack each time the loop occurs? ...

std::map clear() performance in debugger?

The attached, trivial, test program tests the performance of emptying a simple std::map. Using MSVC 2008 and 2010, the debug build will take <30seconds when executed from a command prompt but almost 3 minutes when executed from within the debugger. The call to clear() is entirely responsible for the difference. If I break into the debugg...

FTPClient in MFC :GetFile(Download) issue

Hi, I am using CFtpConnection class for creating my FTPClient Library using MFC. I am using GetFile to download file from Server. MY requirement is like if i am downloading 100 MB video from server when 50-60 MB video is downloaded and in between if i play that while it should play upto that particular location what it has downloaded up...

C++ single template specialisation with multiple template parameters

Hallo! I would like to specialise only one of two template types. E.g. template <typename A, typename B> class X should have a special implementation for a single function X<float, sometype>::someFunc(). Sample code: main.h: #include <iostream> template <typename F, typename I> class B { public: void someFunc() { std...

Alternative to stdext::hash_map for performance reasons

Hi All, I'm working on a high performance application where all calls must be justified. I have a map that is used once in the beginning of each transaction to do a lookup that I would like to improve upon. The map is loaded at startup and does not change after that. The key in the map below is an std::string but it can it changed ...

Finding link time bottlenecks

A question I haven't seen answered that I'm finding very interesting. All the other threads seems to discuss forcing the problem, ie switching to dynamic linking or just distributing the workload. I'm more interested in actually finding out what's causing linking to take so long. The problem is that I don't really see any official ways...

Error while inserting into a vector inside a structure in C++

How to insert into the vector assigned inside a structure ? The code is this that I have written struct state{ int time_taken; vector<int>time_live(1); string loc_name; vector<string>loc(1); }; state A[100]; A[flag1]->loc.insert(flag2); A[flag1]->time_live.insert(time); A[flag2]->loc.insert(flag1); A[flag2]->loc.insert(time...

Two classes -How to access the object of one class from another?

I have two classes, TProvider and TEncrypt. The calling application will talk to the TProvider class. The calling application will call Initialise first to obtain the handle mhProvider. I require access to this handle later when i try to perform encryption, as the TEncrypt class donot have access to this handle mhProvider. How can i get ...

Is calling a function as default argument okay?

Background: When working with time, I wanted to pass "now" as an argument when it is known and ask the system if it is not yet known, so I passed it to an argument which as default calls the time-function. This seems to work with GCC (4.1.2) as illustrated in the following code (it looks a bit weird, but examples with time tend to be a b...