c++

filebuf in ifstream and ofstream

How can i set a new char array to be the buffer of a fstream's filebuf, there is a function (setbuf) in the filebuf but it is protected. while searching on the web, some sites mention fstream::setbuf but it doesn't seem to exist anymore. Thanks ...

Optimizing C++ Tree Generation

Hi, I'm generating a Tic-Tac-Toe game tree (9 seconds after the first move), and I'm told it should take only a few milliseconds. So I'm trying to optimize it, I ran it through CodeAnalyst and these are the top 5 calls being made (I used bitsets to represent the Tic-Tac-Toe board): std::_Iterator_base::_Orphan_me std::bitset<9>::test ...

Hoard allocator not "working"?

I'm trying to Hoard allocator to work, but it seems it doesn't. I have a benchmark application that does a lot of dynamic memory management. The execution time for Hoard and glibc memory manager is the same. It makes me wonder if I'm doing the right thing. What I do is... export LD_PRELOAD="/path/libhoard.so" g++ main.cpp -O3 -o bm -l...

Class template specializations with shared functionality

I'm writing a simple maths library with a template vector type: template<typename T, size_t N> class Vector { public: Vector<T, N> &operator+=(Vector<T, N> const &other); // ... more operators, functions ... }; Now I want some additional functionality specifically for some of these. Let's say I want functions x() a...

Safe Cross Thread Signals/Slot C++

It seem that the only implementation that provide Safe Cross-Thread Signals for both the Signal class and what's being called in the slot is QT. (Maybe I'm wrong?). But I cannot use QT in the project I'm doing. So how could I provide safe Slots call from a different thread (Using Boost::signals2 for example)? Are mutex inside the slot ...

A minimalistic smart array (container) class template

I've written a (array) container class template (lets call it smart array) for using it in the BREW platform (which doesn't allow many C++ constructs like STD library, exceptions, etc. It has a very minimal C++ runtime support); while writing this my friend said that something like this already exists in Boost called MultiArray, I tried ...

Test, if object was deleted

Look to the following code, please: class Node { private: double x, y; public: Node (double xx, double yy): x(xx), y(yy){} }; int main() { Node *n1 = new Node(1,1); Node *n2 = n1; delete n2; n2 = NULL; if (n1 != NULL) //Bad test { delete n1; //throw an exception } } There are two pointers n1, n2 pointe...

how to sort STL vector

i want to sort a vector vector<myclass> object; where as myclass contains many int data variables, how can i sort my vector on any specific data variable of myclass. ...

Which casting technique is better for doing casting from upper class to lower class in C++

Hi all, i want to cast from upper class pointer to lower class i.e from the base class pointer to derived class pointer. Should i use "Dynamic_cast" or "reinterpret_cast"? please advice me ...

DrawPrimitive with alpha

I'm trying to draw a line with the DrawPrimitive function in Direct3D. Can I draw tranparent line with the function? If I can, how to design it? ...

How can I know the jpeg quality of the read image using graphicsmagick

when i read a jpeg image using Magick::readImages(...) function. how can i know the estimated jpeg quality of the image ? i know how to set the quality when i wanna write the image, but it is not relevant to the quality of the original image, so for example: when I read an jpeg image that its quality is 80% and I write it using 90% quali...

Is my method for avoiding dynamic_cast<> faster than dynamic_cast<> itself ?

Hi, I was answering a question a few minutes ago and it raised to me another one: In one of my projects, I do some network message parsing. The messages are in the form of: [1 byte message type][2 bytes payload length][x bytes payload] The format and content of the payload are determined by the message type. I have a class hierarchy...

[Qt] Check octal number

Hello, I write simple application in C++/Qt. And i have a text and some octal number in it. My app splits this text by spaces. And i need to check octal numbers from text. How can i select octal numbers from this text with regular expressions? Thank you. ...

embed media player on Gtkmm window (Linux & C++)

Hello everyone, Please help in displaying/embedding the media player in Gtkmm window under linux. The language used is C++. Help would be appreciated Thanks a lot ...

boost timer usage question

I have a really simple question, yet I can't find an answer for it. I guess I am missing something in the usage of the boost timer.hpp. Here is my code, that unfortunately gives me an error message: #include <boost/timer.hpp> int main() { boost::timer t; } And the error messages are as follows: /usr/include/boost/timer.hpp: In m...

C++ instantiation question

Want to verify that my understanding of how this works. Have a C++ Class with one public instance variable: char* character_encoding; and whose only constructor is defined as: TF_StringList(const char* encoding = "cp_1252"); when I use this class in either C++/CLI or C++, the first thing I do is declare a pointer to an obje...

Printing values of all fields in C++ structure

Say a simple structure struct abc { int a; char b; } I got some value in a variable defined as its structure and now I want to print below a = [some value] b = [some character] What is the best way to achieve this for an arbitrary structure without having to write a dump...(...) function for each of the structure I en...

C++ static array leading to memory leak?

Lets say I have something like... void foo() { char c[100]; printf("this function does nothing useful"); } When foo is called, it creates the array on the stack, and when it goes out of scope, is the memory deallocated automatically? Or is c destroyed, but the memory remains allocated, with no way to access it/get it back exce...

text from a file turned into a variable?

If I made a program that stores strings on a text file using the "list"-function(#include ), and then I want to copy all of the text from that file and call it something(so I can tell the program to type in all of the text I copied somewhere by using that one variable to refer to the text), do I use a string,double,int or what do I decla...

C++ Reference of vector

Hello, class Refvect { public: vector<int> &refv; Refvect(int t, vector<int> &refv = vector<int>()) : refv(refv) { }; void operator()() { refv.clear(); } }; int main () { Refvect r(0); r(); } With Visual Studio 2010, this gives me an error : "vector iterators incompatible" at the execution, but I d...