c++

bad_alloc exception when trying to print the values

I've debugged my other problem back, to the MyMesh constructor. In this code: if (hollow) { numTriangles = n*8; triangles=new MyTriangle[numTriangles]; if (smooth) numSurfacePoints=n*8; else numSurfacePoints=n*12; surfacePoints=new SurfacePoint[numSurfacePoints]; }else { numTriangles = n*4; triangles=new MyTr...

pass a string from managed C# to managed C++

hello, what is the preferred method to pass a string between C++ and C#? i have a c++ class where one of the functions takes a char const * const as parameter. how would i call this function in C#? just using a c#-string doesnt seem to work as the function in C# requires a sbyte* C++ class: public ref class MyClass { public: void S...

mem_fun and bind1st problem

I've following class: class A { public: // ctr and etc ... A* clone(B* container); }; Now, I've a vector<A*> availableObjs populated already. I want to call clone on each of those, so and insert cloned objects into a new container clonedObjs of type vector<A*>. I'm trying following - but it doesn't compile: transform(availableObjs....

What are the effects of incorrectly setting the netmask?

What are the effects of incorrectly setting the netmask? I have a C++ application that sets the network mask of a device. If the netmask is set incorrectly, tftp doesn't seem to work properly. Why would this happen? What other problems occur when the netmask is not properly set for a device/PC? ...

Loop through MFC Child Dialogs, MDIFrames and etc

Hello, Is there a way to loop through all MFC Child Dialogs, MDI frames and etc? And is there a way to find out which dialog or window I am looping through? Any answer would be appreciated! ...

c++ Mysql C API Connection Question

I'm building an application which uses Mysql, I was wondering what would be the best way to manage the connection to the actual Mysql server? I'm still in the design phase, but currently I have it Connecting (or aborting if error) before every query and disconnecting after which is just for testing as right now I'm only running 1 query ...

kcachegrind for RHEL 5.1

I'm about to perform profiling to application. I have vagrind, but kcachegrind is not installed. Tryied to compile without success. Where it can be obtained from for RHEL 5.1? ...

Recovering from stack overflow on Mac OS X

Hi all, I am implementing a cross platform scripting language for our product. There is a requirement to detect and properly handle stack overflow condition in language VM. Before you jump in and say make sure there is no stack overflow in the first place, re-read my first sentence - this is a scripting language and end users may write ...

C# DllImport MFC Extension DLL & Name Mangling

I have a MFC extension DLL which I want to use in a C# application. The functions I'm exposing are C functions, i.e. I'm exporting them like this extern "C" { __declspec(dllexport) bool Initialize(); } The functions internally uses MFC classes, so what do I have to do to use the DLL in C# using P/Invoke. Secondly, I want to use func...

How to efficiently generate random subsets of rows from a matrix

Hi all, I have a large matrix M implemented as vector<vector<double> with m rows, i.e. the matrix is a vector of m vectors of n column elements. I have to create two subsets of the rows of this matrix, i.e. A holds k rows, and B the other m-k rows. The rows must be selected at random. I do not want to use any libraries other than STL...

Is there any way that Enter/LeaveCriticalSection could leave a handle behind

I have the following code in my program: EnterCriticalSection(&critsec[x]); // stuff LeaveCriticalSection(&critsec[x]); It works fine 99.999% of the time but occasionally a handle seems to get left behind. Now I have done the obvious things like make sure that x did not change value between the enter and make sure that there isn...

Is it possible to debug core dumps when using Java JNI?

My application is mostly Java but, for certain calculations, uses a C++ library. Our environment is Java 1.6 running on RedHat 3 (soon to be RedHat 5). My problem is that the C++ library is not thread-safe. To work around this, we run multiple, single-threaded "worker" processes and give them work to do from a central Work Manager, also...

LNK2019 problem

I have a LNK2019 problem when trying to use some DLL in my project. Details: I have a DLL project called dll1; that compiled just fine (using __declspec(dllexport)) in order to export the class inside dll1 (for dll2 usage). I have another DLL project dll2 that uses dll1's functionality. I specified the *.dll1.lib file path inside the...

C++ Redirect Output

Is there a way to redirect c++ output inside the code? The situation is this, I am using some external .cpp and .h files which use printf's to put warnings to console. I wish to redirect "only" these outputs (not mine) to a file "without" modifying their code. So; in my program, I can redirect ouput to a file, and when I will put some o...

aio_write on linux with rtkaio is sometimes long

I'm using async io on linux with rtkaio library. In my tests everything works perfectly, but, in my real application i see that aio_write which is supposed to return very fast, is very slow. It can take more than 100 milis to write a 128KB to a O_DIRECT padded file. Both my test and the application use same I/O size, i check on the same ...

Problem retuning a vector from a c++ dll to another c++ exe

Hi, I have a function foo() in dll A.dll, whose definition is as follows vector<CustomObject> foo() { vector<CustomObject> customObjectCollection; //code which populates customObjectCollection goes here return customObjectCollection; } I am referring this method vector foo() of dll A from exe B When i make a call...

Simple interface for getting HTML content in Boost.Asio

There are a lot of examples how to make HTTP request to a server and get reply via boost.asio library. However, I couldn't find a good example of simple interface and wondering, if I need to implement it myself. For instance, if I need to get content of http://www.foo.bar/path/to/default.html, is there any way to get a content without v...

C++ Pascal's triangle

Hello, I'm looking for an explanation for how the recursive version of pascal's triangle works The following is the recursive return line for pascal's triangle. int get_pascal(const int row_no,const int col_no) { if (row_no == 0) { return 1; } else if (row_no == 1) { return 1; } else if (col...

Why do you prefer char* instead of string, in C++?

I am a C programmer,now trying to write c++ code.I heard string in C++ was better than char* in terms of security, performance, etc,but sometimes it seems that char * is better choice.Someone suggest that programmer should not use char * in C++ becuase we could do all things that char * could do with string, and its securer and faster. ...

boost filtering_istream gzip_decompressor uncompressed file size

I am using the boost filtering stream object to read gzipped files. Works great! I would like to display a progress bar for the amount of the file that has been processed. I need find the input uncompressed file size. Does the gzip decompressor have access to the original file size from the gzipped file? I couldn't find it on the boo...