c++

Shared Memory Example for Symbian

Hi I would like to share some memory between two processes. Unfortunately I cannot find any useful examples when using google. The only thing that comes up is how P.I.P.S can be used. But I remember that it could be done in another way, similar to the one of creating of message queues. Would be great if someone could point me in the rig...

C# vs. C++ in a cross-platform project

My team is planning to develop an application that is initially targeted for Windows but will eventually be deployed cross-platform (Mac, Linux and potentially embedded devices). Our decision is whether to use C#/.NET or generic C++ (with Qt as the user interface library). We’re projecting that by using C#, we can develop our product f...

How to read partial data from large text file in C++

I have a big text file with more then 200.000 lines, and I need to read just a few lines. For instance: line 10.000 to 20.000. Important: I don´t want to open and search the full file to extract theses lines because of performance issues. Is this possible? ...

Why do libraries implement their own basic locks on windows?

Windows provides a number of objects useful for synchronising threads, such as event (with SetEvent and WaitForSingleObject), mutexes and critical sections. Personally I have always used them, especially critical sections since I'm pretty certain they incur very little overhead unless already locked. However, looking at a number of libr...

Why is Boost scoped_lock not unlocking the mutex?

I've been using boost::mutex::scoped_lock in this manner: void ClassName::FunctionName() { { boost::mutex::scoped_lock scopedLock(mutex_); //do stuff waitBoolean=true; } while(waitBoolean == true ){ sleep(1); } //get on with the thread's activities } Basically it sets waitBoolean, and the ...

Address of register variable

In C, we cannot use & to find out the address of a register variable but in C++ we can do the same. Why is it legal in C++ but not in C? Can someone please explain this concept in-depth. Thanks, Naveen ...

C++ Developer Tools: The Dark Areas

While C++ Standards Committee works hard to define its intricate but powerful features and maintain its backward compatibility with C, in my personal experience I've found many aspects of programming with C++ cumbersome due to lack of tools. For example, I recently tried to refactor some C++ code, replacing many shared_ptr by T& to rem...

stl vector.push_back() abstract class doesn't compile

Hi, Let's say I have an stl vector containing class type "xx". xx is abstract. I have run into the issue where the compiler won't let me "instantiate" when i do something like the following: std::vector<xx> victor; void pusher(xx& thing) { victor.push_back(thing); } void main() { ; } I assume this is because the copy constru...

c++ strange c0000005 error

Hello, I am working on a project that can start a program on the winlogon desktop. The program works perfectly while debugging but when I start it outside the ide it fails strangly with the infamous c0000005 error. The weirdest thing though is it doesn't seem to occur on any particular line. Here is the code: #include "stdafx.h" #includ...

Catching a WM_NOTIFY message from a custom ListCtrl

My application is c++, and is a combination of MFC and ATL. The part I'm working with here is MFC. I have a custom list control class in one of my dialogs which inherits from CListCtrl. I'm trying to add a handler for the LVN_ITEMCHANGED message so I can update the rest of the dialog form, which is dependant on the contents of the list...

C++: 2D arrays vs. 1D array differences

I have an array of float rtmp1[NMAX * 3][3], and it is used as rtmp1[i][n], where n is from 0 to 2, and i is from 0 to 3 * NMAX - 1. However, I would like to convert rtmp1 to be rtmp1[3 * 3 * NMAX]. Would addressing this new 1D array as rtmp1[3 * i + n] be equivalent to rtmp1[i][n]? Thanks in advance for the clarifications. ...

Using abstract class as a template type

I'm still pretty new to c++ (coming over from java). I have a stl list of type Actor. When Actor only contained "real" methods there was no problem. I now want to extend this class to several classes, and have a need to change some methods to be abstract, since they don't make sense as concrete anymore. As I expected (from the documenta...

If MessageBox()/related are synchronous, why doesn't my message loop freeze?

Why is it that if I call a seemingly synchronous Windows function like MessageBox() inside of my message loop, the loop itself doesn't freeze as if I called Sleep() (or a similar function) instead? To illustrate my point, take the following skeletal WndProc: int counter = 0; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, ...

Is there a working Semantic Diff tool for C++

I've found only abandoned projects, theories and feature lists. But I could not find a tool which can compare two C++ source files and show semantic differences. Of course I would not compare two unrelated files, or changes accumulated during 10 years of development and maintenance. But changes usually discussed at a code review would ...

how to find allocated memory in linux

Good afternoon all, What I'm trying to accomplish: I'd like to implement an extension to a C++ unit test fixture to detect if the test allocates memory and doesn't free it. My idea was to record allocation levels or free memory levels before and after the test. If they don't match then you're leaking memory. What I've tried so far: I'v...

Array Allocation Subscript Number

Quick question regarding how memory is allocated. If someone were to allocate 20 chars like this: char store[20]; does this mean that it allocated 20 char type blocks of memory, or that it allocated char type blocks of memory starting with 0 and ending with 20. The difference is that the first example's range would be from store[0] t...

Only 2 digits in exponent in scientific ofstream

So according to cplusplus.com when you set the format flag of an output stream to scientific notation via of.setf(ios::scientific) you should see 3 digits plus and a sign in the exponent. However, I only seem to get 2 in my output. Any ideas? Compiled on Mac OS using GCC 4.0.1. Here's the actual code I am using: of.setf(ios::sci...

C++ "conversion loses qualifiers" compile error

I ran into an interesting problem while debugging SWIG typemaps today. Anyone care to enlighten me why Visual C++ 2008 throws a "conversion loses qualifiers" error when converting from ourLib::Char * to const ourLib::Char * &? I thought Type * -> const Type * was a trivial conversion, and (when calling functions) Lvalue -> Lvalue & as we...

Is it legal C++ to pass the address of a static const int with no definition to a template?

I'm having trouble deciding whether not this code should compile or if just both compilers I tried have a bug (GCC 4.2 and Sun Studio 12). In general, if you have a static class member you declare in a header file you are required to define it in some source file. However, an exception is made in the standard for static const integrals. ...

Difference between Foo *foo; and Foo foo; in C++

I know the basics of pointers. I would just like to know when you would use Foo *foo; instead of Foo foo; and what one allows you to do that the other doesn't. Thanks in advance ...