c++

optimize time(NULL) call in c++

Hi, I have a system that spend 66% of its time in a time(NULL) call. It there a way to cache or optimize this call? Context: I'm playing with Protothread for c++. Trying to simulate threads with state machines. So Therefore I cant use native threads. Here's the header: #ifndef __TIMER_H__ #define __TIMER_H__ #include <time.h> #inc...

Need help rewriting a C macro as a function

Hi, I need some help rewriting the following line in a more type safe way and rewriting it as a function, however the fact that this code is defined inside a function is making it hard for me to think of a clever way of doing it because apparently it would involve declaring several arguments. #define CHECK(id) if(table->cells[id]) isgoo...

Do you still trap memory allocation failures in your C++ program

I am writing some guidelines for the company and I need to answer some tough questions. This one is quite difficult. The solution can be: Not track at all. Make sure that objects are allocated using new which will throws an exception when allocation failed. The application will die, and it is not a big deal. PRO - code usually can be...

Can't get SAFEARRAY to work with Interop

I have an ATL COM Server, where the method for the interface is STDMETHODIMP CWrapper::RUN(long iDataSize, SAFEARRAY** iData) and the MIDL for this function looks like [id(1), helpstring("method RUN")] HRESULT RUN([in] long nSize, [in, size_is(nSize)] SAFEARRAY(_MyDataType*)* iData); I import the tlb from this project using tlbimp...

How to build C++ app which runs on plain old XP SP2 with Visual Studio 2008 and no Side-by-Side DLLs?

I'd like to compile a C++ project with just a single call to WinExec in order to launch another executable with some command line parameters. I've no idea what settings to specify in my project in order to get produce an executable that works without requiring Microsoft side-by-side DLLs, which I don't want to have to install on my targe...

C++ display stack trace on exception

I want to have a way to report the stack trace to the user if an exception is thrown. What is the best way to do this? Does it take huge amounts of extra code? To answer questions: I'd like it to be portable if possible. I want information to pop up, so the user can copy the stack trace and email it to me if an error comes up. ...

push_back for vector, deque and lists

I am trying to optimize a C++ routine. The main bottleneck in this routine is the push_back() of a vector of objects. I tried using a deque instead and even tried a list. But strangely (and contrary to theory) deque and list implementations run much slower than the vector counterpart. In fact even clear() runs much slower for the deque ...

Visual Studio unmanaged C++ smart file explorer

I use Visual Studio to develop unmanaged C++ apps for a living. Is there an add-on tool (price isnt the issue) that is smart enough to detect folders that I create within my solution folder and add them to the include path (/I)? It would automatically do this for win32, or x64 platform settings, or debug, and release, etc. It should al...

Convert int64_t to double

int64_t a = 1234; double d = (double) a; Is this the recommended way? ...

Should I comment the declaration or the definition in C++?

Which is more practical to comment, the declaration (in the header file) or the definition (in the source file)? Maybe I should comment both, or comment neither and put it all in a separate file... ...

What are the differences between C, C# and C++ in terms of real-world application

As I posted earlier here I've decided to try my hand at one of these but given my interests as a web developer, I'd like to know the difference between them in their real-world applications. Edit Note: While I'm a web developer, please don't let that limit your answer. I'm 30...I've got years of career changing ahead of me. ...

Is boost shared_ptr <XXX> thread safe?

I have a question about boost :: shared_ptr. There are lots of thread. class CResource { xxxxxx } class CResourceBase { public: void SetResource(shared_ptr<CResource> res) { m_Res = res; } shared_ptr<CResource> GetResource() { return m_Res; } private: shared_ptr<CResource> m_Res; } CResourceBase base; ...

C++ template static pointer-to-member initialization

I have a template class which has a static pointer-to-member, like this: template<class T, T* T::*nextptr> class Queue { T* head; T* tail; static T* T::*pnext; }; My question is how to write the initializer of the static pointer-to-member. I tried the obvious case: template<class T, T* T::*nextptr> T* Queue<T, nextptr>::*...

Naming conventions for template types?

Traditionally, the names of template types are just a single upper-case letter: template<class A, class B, class C> class Foo {}; But I hesitate to do this because it's non-descriptive and hard therefore to read. So, wouldn't something like this be better: template<class AtomT, class BioT, class ChemT> class Foo {}; I also tend to ...

Vector of pointers problem

Hi, I am having quite a bit of trouble with trying to push_back an object of my custom class to a vector of pointers with my custom class as the type. Please see the code below along with the error received. I am using Eclipse with the CDT plugin and OpenCV on windows xp. I have spent so much time trying to find an answer but to no ava...

Volume Shadow Copy (VSS)

Can anyone clarify an issue? I'm using the VSS API (C++ using VSS2008 and the latest SDK running on XP SP3) in a home-brew backup utility*. THe VSS snapshot operations work fine for folder that have no subfolders - i.e. my email and SQL server volumes. However when I take a snapshot of a folder that does contain subfolders, the nested ...

TCP: How are the seq / ack numbers generated?

Greetings and salutations! I am currently working on a program which sniffs TCP packets being sent and received to and from a particular address. What I am trying to accomplish is replying with custom tailored packets to certain received packets. I've already got the parsing done. I can already generated valid Ethernet, IP, and--for the...

Cross-platform C++ IDEs?

I'm looking for a good IDE for C++ that has most or all of the following properties (well, the first 4 or 5 ones are mandatory): cross-platform (at least Mac, Linux) of course, syntax highlighting and other basic coding editor functionality reasonably responsive GUI, not too sluggish on mid-size (say, 100 files) projects (both my Linux...

How can I code my own custom splash screen for Linux?

This is NOT a question on plain old boring customization; I actually want to create an program, you know, with source code, etc... I'm thinking about programming my own media centre interface, and I figured it'd look better if I coded my own splash screen for when the OS is loading. Note: The media centre interface will be run in X...

Seeking suggestions for Unit Testing C++ app spread over several dlls

New to unit testing and have an app that is spread out over several dlls. What are some suggestions for unit testing the app? If I put the unit tests in their own project, i can only test the published interface for each dll. Is that what most people do? Or should I put the unit tests in with the code in the dlls and test there? Wha...