c++

strings.h and wrapping this macro with a macro check of whether

I infer from Google search results that strings.h (from here) is for UNIX systems. I would like to wrap the following line with a macro check of whether the host's operating system is Linux/UNIX. It would be much appreciated to hear suggestions about it. Thanks in advance. #include <strings.h> ...

What does static_assert do, and what would you use it for?

Could you give an example where static_assert(...) 'C++0x' would solve the problem in hand elegantly? I am familiar with run-time assert(...). When should I prefer static_assert(...) over regular assert(...)? Also, in boost there is something called BOOST_STATIC_ASSERT, is it the same as static_assert(...)? ...

Efficient file transfer from Java server to multiple C++ clients?

I need to transfer files fast over the Internet from a Java server to C++ clients, where often many clients would need the same files. I was looking at say transferTo() in Java which sounds like it would be a decently optimized function to send files. However, I'm not sure when I use transferTo() how to best receive that in C++ (i.e. i...

C++ boost::thread and automatically locking containers

Is there a way to automatically lock an STL container on access, without having to lock and release around it? ...

QTimer vs individual threads

My program's really consuming CPU time far more than I'd like (2 displays shoots it up to 80-90%). I'm using Qtimers, and some of them are as short as 2ms. At any given time, I can have 12+ timers going per display -- 2ms, 2ms, 2ms, 250ms, the rest ranging between 200ms and 500ms. Would it be better if I used threads for some or all of t...

Segmentation fault when catching exceptions in a libpthread linked app ( linux, C++ )

Hi I have this piece of code here: These are functions used to create and stop a pthread: void WatchdogController::conscious_process_handler_start() { if ( debug ) cout << "WatchdogController: starting conscious process thread" << endl; cn_pr_thread_active = true; if ( pthread_create( &cn_pr_thread, NULL, conscious_proc...

How do I controll clipping with non-opaque graphics-item's in Qt?

I have a bunch of QGraphicsSvgItem's in a QGraphicsScene that are drawn connected by QGraphicsLineItem's. This show's a graph of a tree-structure. What I want to do is provide a feature where everything but a selected sub-tree becomes transparent. A kind of "highlight this sub-tree" feature. That part was easy, but the results are ugly ...

techniques for obscuring sensitive strings in C++

I need to store sensitive information (a symmetric encryption key that I want to keep private) in my C++ application. The simple approach is to do this: std::string myKey = "mysupersupersecretpasswordthatyouwillneverguess"; However, running the application through the strings process (or any other that extracts strings from a binary ap...

How to code Jon Skeet's Singleton in C++?

On Jon's site he has thisvery elegantly designed singleton in C# that looks like this: public sealed class Singleton { Singleton() { } public static Singleton Instance { get { return Nested.instance; } } class Nested { // Explicit static constructor to tell C#...

How to implement Copy-on-Write?

Hey! I want to implement a copy-on-write on my custom C++ String class, and I wonder how to... I tried to implement some options, but they all turned out very inefficient. Thank you guys :-) ...

Searching a C++ Vector<custom_class> for the first/last occurence of a value

Hi, I'm trying to work out the best method to search a vector of type "Tracklet" (a class I have built myself) to find the first and last occurrence of a given value for one of its variables. For example, I have the following classes (simplified for this example): class Tracklet { TimePoint *start; TimePoint *end; int angle...

Is there a good way to avoid duplication of method prototypes in C++?

Most C++ class method signatures are duplicated between the declaration normally in a header files and the definition in the source files in the code I have read. I find this repetition undesirable and code written this way suffers from poor locality of reference. For instance, the methods in source files often reference instance variabl...

Create a new EXE from within C

Am working in VC++ 2008 (express) and I would like to write something in C that creates an "empty" exe that I can later call LoadLibrary on and use BeginUpdateResource, UpdateResource, EndUpdateResource to modify the contents. Just writing a 0-byte file doesn't allow me to open it with LoadLibrary because it isn't a resource. ...

c++ Debugging Exception c0000139

Hi, I am currently trying to get to the bottom of a client crash with one of our applications. I have wrapped the app in an exception handler which creates a mini-dump when the crash occurs. The application crashes with the exception c0000139 (of which there isn't a huge amount of documentation). The callstack looks like this ntdll....

How do I ensure buffer memory is aligned?

I am using a hardware interface to send data that requires me to set up a DMA buffer, which needs to be aligned on 64 bits boundaries. The DMA engine expects buffers to be aligned on at least 32 bits boundaries (4 bytes). For optimal performance the buffer should be aligned on 64 bits boundaries (8 bytes). The transfer size must be a m...

Sorting blocks of L elements

I have an array of N * L integers int array[N * L]; I want to divide the array in N blocks of L elements and sort the blocks according to the classic list comparison (compare first element, than second, etc). In C I can do: qsort(array, N, sizeof(int) * L, comp); How can I achieve the same result using C++ std::sort(...) which is,...

c++: Initialize struct with one array containing all arguments

Hi, I am currently working on a small tokenizer template function which also casts the tokens to different objects. this works really nice aslong as all the strucs I cast to have the same number of items. what I would like to do know is to make the function cast to structs with any number of items. The bottleneck of the function for me ...

CreateTexture loading bitmap problem

I have the following function it takes 3 arguments being a texture array, filename and texture id but when I invoke the function using: CreateTexture(g_Texture, "\\\\nsq021vs\\u2\\abcb433\\MyDocs\\Visual Studio 2008\\Projects\\CaptainEdsAdv\\CaptainEdsAdv\\Back.bmp", BACK_ID ); it returns this: - pBitmap 0xcccccccc {sizeX=???...

In native C++, how does one use a SqlCe .sdf database?

Is there a simple way, without .NET? I've found some libraries but none for SqlCe 3.5. There is http://sqlcehelper.codeplex.com/ but it's far from done, since a major feature like using a password is not yet implemented. I've looked at the source and it uses OLEdb to handle the database. The offical Microsoft Northwind example (that is...

how to convert CString to Bytes

i am actually tryin to convert a csharp code to c... below is the C# code.. CString data = "world is beautiful"; Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data); in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? P...