c++

local variables of static member functions

Today we came accross a problem concerning static member functions in an multithreaded environment. The question we asked ourselves and couldn't find a satisfying answer is: are local varialbes of static member functions static as well? // header class A { static int test(); } // implementation int A::test() { int a = rand(); in...

Memory Freeing Inqury

Additional thanks extend to Daniel Newby for answering my memory usage question (and Martin York for explaining it a bit more). It is definitely the answer I was looking for, but more of my other questions were answered by others. Thanks everyone for clearing up all of my concerns. Very pleased to see things running how I expect them t...

not waiting for keyboard input (overloaded input stream operator) in C++

Just a quick question. I have developed the following code: #pragma once #include <iostream> using namespace std; class Percent { public: friend bool operator ==(const Percent& first, const Percent& second); friend bool operator <(const Percent& first, const Perc...

Locating what lib is linking to the debug CRT

We link our app with numerous different static libs, the problem is that one of these libs is in turn linking with the VC90.DebugCRT even in release. Some libs we don't even have the source to, so it would be nice if there's a way to locate what lib is the actual culprit. I've toyed around some with dumpbin, but am unable to find a way t...

Storing vector in a struct C++

Why can't I do this: struct sName { vector<int> x; }; It takes only three pointers to store a vector, so I should be able to do this? ...

Loading large multi-sample audio files into memory for playback - how to avoid temporary freezing

I am writing an application needs to use large audio multi-samples, usually around 50 mb in size. One file contains approximately 80 individual short sound recordings, which can get played back by my application at any time. For this reason all the audio data gets loaded into memory for quick access. However, when loading one of these f...

[C++] Priority Queue Wrong Order

I am programming the huffman encoding. This is the beginning of my program: using namespace std; //Counting methods int *CountCharOccurence(string text) { int *charOccurrence = new int[127]; for(int i = 0; i < text.length(); i++) { charOccurrence[text[i]]++; } return charOccurrence; } void DisplayCharOccure...

is there a new equalivant of _malloca

I am a big fan of the _malloca but I can't use it with classes. Is there a stack based dynamic allocation method for classes. Is this a bad idea, another vestige of c which should ideologically be opposed or just continue to use it for limited purposes. ...

sizeof() a vector

Hello! I have a vector<set<char> > data structure (transactions database) and I want to know the size of it. When I use sizeof() with each set<char> the size is 24 in spite of the set contains 3, 4 or 5 chars. Later, when I use sizeof() with the vector<set<char> > the size is 12... I suppose this is not the way to know the size of a data...

Am I using delete correctly here?

I've just started combining my knowledge of C++ classes and dynamic arrays. I was given the advice that "any time I use the new operator" I should delete. I also know how destructors work, so I think this code is correct: main.cpp ... int main() { PicLib *lib = new PicLib; beginStorage(lib); return 0; } void beginStorage...

Heap corruption issues

Inside my template function I have the following code: TypeName myFunction() { TypeName result; void * storage = malloc( sizeof( TypeName ) ); /*Magic code that stores a value in the space pointed to by storage*/ result = *(TypeName *)storage; free( storage ); return result; } This causes an "HEAP CORRU...

problem with memcpy'ing from shared memory in boost.interprocess

This is driving me wild with frustration. I am just trying to create a shared memory buffer class that uses in shared memory created through Boost.Interprocess where I can read/store data. I wrote the following to test the functionality #include <boost/interprocess/shared_memory_object.hpp> #include <boost/interprocess/mapped_region.hpp...

fast java/python/C++ ipc

I notice this thread: Fastish Python/Jython IPC, and I have a similar problem, but in different language. I have a Java front-end and a C++ back-end, which I am thinking about rewrite it in Python in some near future. What will be the best IPC? I prefer socket to HTTP, as I am trying to avoid the HTTP overhead. And XML-RPC is an example...

limit the creation of object on heap and stack in C++

Hi, I have a question about how to limit the creation of object on heap or stack? For example, how to make sure an object not living on heap? how to make sure an object not living on stack? Thanks! ...

C++ static const and initialization (is there a fiasco)

Hi all, I am returning to C++ after a long absence and I am stumbling a little over my understanding of the fairly well known static initialization problem. Let's say I have a simple class Vector2 as given below (note that I am aware that x and y should be private with getters and setters, these have just been omitted for brevity): cl...

Is C++ still actively used for general purpose development?

Possible Duplicate: Which sector of software industry uses C++? C++ was for many years the holy grail of mission critical high performance development. However, it seems that for the past 10 years like much of the development world has moved to Java and C#. My quesiton is this, is C++ effectively relegated to embedded system...

Calling this->get/this->set methods versus directly accesing member variables in C++

Suppose I have a class Foo, with a private variable bar_ containing some state for Foo. If necessary, I may write public get/set methods for bar_. Naturally, I avoid this as much as possible to maintain encapsulation. Assuming I have these get/set methods, whenever I have to access or modify bar_ within a method belonging to Foo, I usua...

one question about default value in C++

I have some questions about the default values in a function parameter list 1) Is the default value a part of the signature? What about parameter type of the default parameters? 2) Where are the default value stored? In the stack or or global heap or in the constant data segment? Thanks! ...

how to make data structures persistent in c++?

how to make data structures(like trees, graphs ) persistent in c++? ...

Memory management for collections of widgets in Qt

Sorry for the dumb question, but I'm working with Qt and C++ for the first time, and working through the tutorial and some samples. One thing that was mentioned was that Qt stuff doesn't need to be explicitly deleted. So, main question, does this also apply to collections of Qt stuff? Like say I want a dynamic number of MyWidgets, so I ...